【发布时间】:2017-05-24 22:31:11
【问题描述】:
我想知道在boost::hana::when<false> 案例没有案例库的情况下,when 专业化如何工作。
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> 更专业的。
我已经完成了很多元函数,并使用了特化和参数包以及排序,但在这种情况下,有些东西我看不到。
如果false 案例没有默认实现,我不明白为什么when 模板的true 或false 值很重要。
【问题讨论】:
标签: c++ boost c++14 partial-specialization