我想确保我正确理解约束规范化过程,因为 cppreference 在这个主题上有点模糊。
似乎在规范化过程中,requires
中的任何内容表达式总是被认为是一个原子,无论多么具体/复杂。
这似乎得到了以下不同处理的支持:
template<typename T>
concept Decrementable = requires(T t) { --t; };
template<typename T>
concept RevIterator = Decrementable<T> && requires(T t) { *t; };
template<typename T>
concept RevIterator2 = requires(T t) { --t; *t; };
哪里Decrementable < RevIterator
但是 Decrementable
和 RevIterator2
没有订购。那么,这是正确的吗?或者有人可以指出我谈论这个的标准的特定部分吗?
最佳答案
是的,你的理解是正确的。要使包含(您用 <
表示)发生,约束表达式的范式之间必须存在某种关系。如果检查约束规范化过程:
[temp.constr.normal]
1 The normal form of an expression E is a constraint that is defined as follows:
- The normal form of an expression
( E )
is the normal form ofE
.- The normal form of an expression
E1 || E2
is the disjunction of the normal forms ofE1
andE2
.- The normal form of an expression
E1 && E2
is the conjunction of the normal forms ofE1
andE2
.- The normal form of a concept-id
C<A1, A2, ..., An>
is the normal form of the constraint-expression ofC
, after substitutingA1
,A2
, ...,An
forC
's respective template parameters in the parameter mappings in each atomic constraint. If any such substitution results in an invalid type or expression, the program is ill-formed; no diagnostic is required.
[ ... ]- The normal form of any other expression
E
is the atomic constraint whose expression is E and whose parameter mapping is the identity mapping.
人们看到逻辑 AND 表达式、逻辑 OR 表达式和概念 ID 是唯一被“分解”的表达式。所有其他类型的表达式几乎都形成了自己的原子约束,包括
requires
表达如 requires(T t) { --t; *t; }
.
关于c++ - 规范化约束时,需要表达式是原子吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69184830/