结构/类的名称,进行编译时计算

时间:2019-05-15 12:31:42

标签: c++ templates naming

我想评论我的模板库资源。它提供类型容器和与其一起使用的功能。例如:

template <class TypePair>
struct first;

template <class TypePair>
using first_t = typename first<TypePair>::type;

template <
    template <class, class> class TypePair,
    class First,
    class Second
>
struct first<TypePair<First, Second>>
{
    using type = First;
};

用法:

using my_pair = type_pair<int, double>;
using first_entry = first_t<my_pair>;
static_assert(std::is_same_v<int, first_entry >);

这是对类型的编译时间计算。我怎么称呼这样的东西?有一个通用的词吗?我了解类型特征,但我认为这个术语在这里是正确的。

预先感谢, 马丁

0 个答案:

没有答案
相关问题