0
静态断言全部失败。 Constifier
是什么类型的函数指针创建?将常量添加到函数指针会发生什么?
#include <type_traits>
template<typename T>
struct Constifier;
template<typename T>
struct Constifier<T *>
{
typedef const T *Type;
};
int main()
{
static_assert(std::is_same<typename Constifier<int (*)()>::Type, const int (*)()>::value, "");
static_assert(std::is_same<typename Constifier<int (*)()>::Type, int (*const)()>::value, "");
static_assert(std::is_same<typename Constifier<int (*)()>::Type, void>::value, "");
}
在你的trait中,你并没有为const *指针*添加常量,而是添加了*指向*函数,但函数类型的顶级cv限定符被忽略(尽管你可以有一个指向函数的const指针,你会使用'typedef T * const Type')。顺便说一句。这里不需要'typename'关键字。 –
@PiotrSkotnicki我看,它不是依赖类型。 – xiver77