Is the body of a concept definition or require block unevaluated context? eg. can I use std::declval
safely?
template<typename T>
concept bool SomeConcept = requires(T a) {
{ a.someFunction(std::declval<int>()) } -> int;
};
Yes. From [temp.constr.expr], wording as of N4641:
An expression constraint is a constraint that specifies a requirement on the formation of an expression
E
through substitution of template arguments. An expression constraint is satisfied if substitution yieldingE
did not fail. Within an expression constraint,E
is an unevaluated operand (Clause 5).
So using declval
should be fine.
Alternatively, you could just create objects of the types you need since in the context of requirements, we're not actually constructing anything:
template<typename T>
concept bool SomeConcept = requires(T a, int i) {
{ a.someFunction(std::move(i)) } -> int;
};
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