0
我需要一个类型trait,确定一个类是否是给定模板的专业化。 This answer提供了一个适用于大多数情况下的实现。is_specialization类型trait为静态constexpr成员
但是,它似乎不适用于静态constexpr成员类型。在下面的例子中(也wandbox可用),最后static_assert上锵和GCC主干失败:
#include <type_traits>
// from https://stackoverflow.com/questions/16337610/how-to-know-if-a-type-is-a-specialization-of-stdvector
template<typename Test, template<typename...> class Ref>
struct is_specialization : std::false_type {};
template<template<typename...> class Ref, typename... Args>
struct is_specialization<Ref<Args...>, Ref>: std::true_type {};
template<typename T>
struct bar {
bool x;
};
struct foo {
bar<int> y;
static constexpr bar<bool> z{true};
};
int main() {
static_assert(is_specialization<decltype(foo::y), bar>{});
static_assert(is_specialization<decltype(foo::z), bar>{});
}
我有两个问题:这是正确的行为,我怎么可以写一个类型的特点,将工作时我指的是一个静态constexpr成员的类型?