struct is {
template<typename T>
static constexpr bool _vector() {
if constexpr (std::is_fundamental_v<T>) {
return false;
} else {
return std::is_same_v<T, std::vector<typename T::value_type>>;
}
}
template<typename T>
static constexpr bool vector = _vector<T>();
template<typename T>
static constexpr bool vector2 = std::is_fundamental_v<T> || (!std::is_fundamental_v<T> && std::is_same_v<T, std::vector<typename T::value_type>>);
};
int main(int argc, const char * argv[]) {
std::cout << is::vector2<std::vector<std::vector<int>>::value_type::value_type> << std::endl;
return 0;
}
使用 vector 是 ok 的
使用 vector2 编译会报 Type 'int' cannot be used prior to '::' because it has no members