Reputation: 300
I have a class template that I'd like to write as follows:
template </*what to put here?*/ T>
Class Bar {};
I would like to enforce T to only be a value from a scoped enum.
I used the is_scoped_enum
type check provided here, however the best I was able to come up with was to change Bar
to be like this:
template <typename T>
concept ScopeEnum = is_scoped_enum<T>::value;
template<ScopeEnum SE, SE se>
class Bar {};
How can I implement it so Bar
remains as intended?
Upvotes: 0
Views: 139
Reputation: 170064
Use a generic non-type parameter, and constrain its declaration
template <ScopedEnum auto se>
class Bar {};
Upvotes: 5