<分区>
如果我这样写一个 trait,
template <typename T>
struct is_int {
static constexpr bool value = false;
};
template <>
struct is_int<int> {
static constexpr bool value = true;
};
值
是程序运行时实际存储在内存中的吗?例如,如果我在一百万种不同的类型上使用这个特征,程序是否使用 1 MB 的内存来存储这些值?
换句话说,使用还有什么好处吗
template <typename T>
struct is_int {
enum { value = 0; }
};
template <>
struct is_int<int> {
enum { value = 1; }
};