Can a concept evaluation depend on where it is evaluated?

廉价感情. 提交于 2019-12-12 07:46:56

问题


[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


回答1:


Can a concept evaluation depend on where it is evaluated?

Yes. This was explicitly discussed during core wording review when merging Concepts into the working draft. The concept is re-evaluated every time.

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 well-formed. In other words, we don't "memoize" concepts in the same way we "memoize" template instantiations.



来源:https://stackoverflow.com/questions/53260099/can-a-concept-evaluation-depend-on-where-it-is-evaluated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!