在 C++ 中,如何强制模板参数为作用域枚举值类型?

Ome*_*waz 0 c++ templates c++-concepts c++20

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

template </*what to put here?*/ T>
Class Bar {};
Run Code Online (Sandbox Code Playgroud)

我想强制 T 只能是作用域枚举中的值。我使用了此处is_scoped_enum提供的类型检查,但是我能想到的最好的办法就是更改为如下所示:Bar

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

template<ScopeEnum SE, SE se>
class Bar {};
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现它并Bar保持预期的效果?

Sto*_*ica 5

使用泛型非类型参数,并约束其声明

template <ScopedEnum auto se>
class Bar {};
Run Code Online (Sandbox Code Playgroud)