在C++中,如何强制模板参数是一个有作用域的枚举值类型?

0mkxixxg  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(104)

我有一个类模板,我想写如下:

template </*what to put here?*/ T>
Class Bar {};

我想强制T只能是一个来自限定范围枚举的值。我使用了here提供的is_scoped_enum类型检查,但是我能想到的最好的方法是将Bar更改为如下形式:

template <typename T>
concept ScopeEnum = is_scoped_enum<T>::value;

template<ScopeEnum SE, SE se>
class Bar {};

如何实现它,使Bar保持预期状态?

oknwwptz

oknwwptz1#

使用泛型非型别参数,并限制其宣告

template <ScopedEnum auto se>
class Bar {};

相关问题