[英]Template value before typename
I have following simplified example code where I attempt to figure out whether given value is the maximum value of enum of it's type.我有以下简化的示例代码,我试图找出给定的值是否是它的类型枚举的最大值。
enum class MyEnum : unsigned char {
VALUE,
OTHER_VALUE,
_LAST
};
template<typename T, T _L>
bool is_not_last(T value) {
return value < _L;
}
int main()
{
is_not_last<MyEnum, MyEnum::_LAST>(MyEnum::OTHER_VALUE);
return 0;
}
How can I format template so I can call is_not_last
without specifying type first.如何格式化模板,以便我可以在不先指定类型的情况下调用is_not_last
。
Desired outcome: is_not_last<MyEnum::_LAST>(MyEnum::OTHER_VALUE);
期望的结果: is_not_last<MyEnum::_LAST>(MyEnum::OTHER_VALUE);
Following declarations didn't work:以下声明不起作用:
template<T _L>
bool is_not_last(T value); // Doesn't have typename specified
template<typename T _L>
bool is_not_last(T value); // Invalid syntax
I feel like compiler should be able to deduce type from MyEnum::_LAST
but I haven't been able to figure that out.我觉得编译器应该能够从MyEnum::_LAST
推断类型,但我无法弄清楚。
Thank you very much.非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.