Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the body of requires block unevaluated context?

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;
};
like image 736
Guillaume Racicot Avatar asked Apr 18 '17 15:04

Guillaume Racicot


1 Answers

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 yielding E 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;
};
like image 112
Barry Avatar answered Oct 19 '22 02:10

Barry