Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a concept evaluation depend on where it is evaluated?

[temp.concept]/5 says:

A concept is not instantiated ([temp.spec]). [ Note: An id-expression that denotes a concept specialization is evaluated as an expression ([expr.prim.id]). [...]]

Does it mean that this rule bellow ([temp.point]/8) does not apply?

If two different points of instantiation give a template specialization different meanings according to the one-definition rule, the program is ill-formed, no diagnostic required.


For example if this rule does not apply, this code bellow is well formed:

template<class T>
concept Complete = sizeof(T)==sizeof(T);

struct A;

constexpr inline bool b1 = Complete<A>; //Complete<A>==false;

struct A{};

constexpr inline bool b2 = Complete<A>; //Complete<A>==true;

This question is followed by this one

like image 536
Oliv Avatar asked Nov 12 '18 10:11

Oliv


People also ask

What does concept evaluation mean?

Concept evaluation is the process of evaluating consumers' impressions of a prospective product or service. Concept evaluation can be a critical early step toward discovering if a new product or service will meet the needs and expectations of potential customers.


Video Answer


1 Answers

Can a concept evaluation depend on where it is evaluated?

No.

It used to be the case that this was true (as my answer before this edit stated), but it turns out that this severely inhibits compiler throughput (since you cannot cache the result of a concept check) and the motivation for having it to begin with was pretty weak. This was a very late change, adopted as part of P2104 in the Prague 2020 meeting which adds the following sentence to [temp.constr.atomic]:

If, at different points in the program, the satisfaction result is different for identical atomic constraints and template arguments, the program is ill-formed, no diagnostic required.

As a result, this:

template<class T>
concept Complete = sizeof(T) == sizeof(T);

struct A;
static_assert(!Complete<A>);
struct A {};
static_assert(Complete<A>);   

is ill-formed, NDR (practically speaking, Complete<A> will still be false after A becomes complete). In other words, we "memoize" concepts in the same way we "memoize" template instantiations.

like image 70
Barry Avatar answered Oct 21 '22 22:10

Barry