【发布时间】:2020-07-31 18:12:42
【问题描述】:
我的代码可以根据 C++ 类型识别您需要使用的 GL 类型。我想制作它的_t 版本(如std::decay_t 或std::enable_if_t)但公开int 常量值
template <typename T, typename = void> struct GLType {};
template <typename T>
struct GLType<T, std::enable_if_t<std::is_same_v<std::remove_pointer_t<std::decay_t<T>>, float>>> {
const static constexpr int type = GL_FLOAT;
};
template <typename T>
struct GLType<T, std::enable_if_t<std::is_same_v<std::remove_pointer_t<std::decay_t<T>>, double>>> {
const static constexpr int type = GL_DOUBLE;
};
我的第一次尝试是
template <typename T>
using GLType_t = GLType<T>::type;
但这不起作用。甚至可以以相同的方式返回值而不是类型吗?
最后,我想要类似的东西
int a = GLType_t<float>;
// instead of
int a = GLType<float>::type; // which works fine btw
【问题讨论】:
-
根据 POSIX 标准,以 _t 结尾的名称是为实现而保留的,因此如果您的目标是 POSIX 系统(例如 Linux),则不应以 _t 结尾。
-
@jesperjuhl 感谢您提供的信息,但无论如何我将其更改为 _v
标签: c++ templates struct template-meta-programming sfinae