我想知道when
专业化是如何在boost::hana::when<false>
案例没有案例基础的情况下工作的。boost :: hana tag_of implementation
boost::hana::tag_of
实现:
template<bool condition>
struct when; // forward declaration only
template<typename T, typename = void>
struct tag_of;
template<typename T, typename>
struct tag_of : tag_of<T, when<true> >
{};
template<typename T, bool condition>
struct tag_of<T, when<condition> >
{
using type = T;
};
和测试例如:
struct my_tag {};
struct my_tag2 {};
namespace boost {
namespace hana {
template<class T>
struct tag_of<T, when<std::is_same<T, int>{}()> >
{
using type = my_tag;
};
template<class T>
struct tag_of<T, when<std::is_same<T, unsigned>{}()> >
{
using type = my_tag2;
};
}
}
int main()
{
using type = boost::hana::tag_of<int>::type;
std::cout << std::is_same<type, my_tag>{} << std::endl;
}
,我不知道为什么std::is_same<T, int>{}()
(或::value
这是相同的),是一个更专业的偏特比std::is_same<T, unsigned>{}()
,以及为什么,如果两种情况的条件都是错误的,when<condition>
更专业。
我已经完成了许多元函数,并且使用了专业化和参数包以及排序,但在这种情况下,有些东西我看不到。
的事情是,我不明白为什么when
模板的true
或false
值能够决定的事情,如果有对false
情况下,没有默认实现。
这是惊人的美丽。谢谢。 –