<分区>
我觉得有趣的是,这种类型特征与 std::array 不匹配(它会产生编译错误),但它适用于 unordered_map。这是为什么?
#include <iostream>
#include <unordered_map>
#include <array>
template <typename T, 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 {
};
int main()
{
using T = std::unordered_map<int, int>;
using C = std::array<int, 2>;
auto value = is_specialization<T, std::unordered_map>::value;
std::cout << "Is type of unorderd map specialization? : " << std::boolalpha << value << std::endl;
auto secondValue = is_specialization<C , std::array>::value;
std::cout << "Is type of array specialization? : " << std::boolalpha << secondValue << std::endl;
}