Can a concept evaluation depend on where it is evaluated?

后端 未结 1 1604
天涯浪人
天涯浪人 2021-02-12 22:00

[temp.concept]/5 says:

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

相关标签:
1条回答
  • 2021-02-12 22:50

    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.

    0 讨论(0)
提交回复
热议问题