How to get a core-constant expression of type bool from a concept and a type?
template<class T>
concept Valid = requires(T t) {
{ t.x };
};
struct ValidExample { int x; };
struct InValidExample {};
static_assert(?); // ValidExample is Valid
static_assert(?); // InValidExample is not Valid
I'm starting to play with concepts, and I'd like to check a type against a concept (to be more precise: to define a trait from a concept). How to do so?
You might use:
static_assert(Valid<ValidExample>); // ValidExample is Valid
static_assert(!Valid<InValidExample>); // InValidExample is not Valid
as template variables (of type bool
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With