概念评估可以取决于在哪里进行评估吗? [英] Can a concept evaluation depend on where it is evaluated?

查看:74
本文介绍了概念评估可以取决于在哪里进行评估吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[temp.concept]/5 说:

未实例化概念([temp.spec]). [注:表示概念专业化的id表达式被评估为表达式([expr.prim.id]). [...]]

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

是否表示此规则如下( [ temp.point]/8 )不适用?

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;

这个问题之后是这个一个

推荐答案

概念评估可以取决于评估的地方吗?

Can a concept evaluation depend on where it is evaluated?

不.

过去通常是这样(如我在此编辑之前的回答所述),但事实证明,这严重抑制了编译器的吞吐量(因为您无法缓存概念检查的结果)以及具有这种动机.首先,它是非常薄弱的​​.这是一个很晚的更改,被作为 P2104 在2020年布拉格会议上,在[temp.constr.atomic]中添加以下句子:

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.

结果是:

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

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

是格式错误的NDR(实际上,A完成后,Complete<A>仍将是false).换句话说,我们以记忆"模板实例化的方式记忆"概念.

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.

这篇关于概念评估可以取决于在哪里进行评估吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆