c++ - 规范化约束时,需要表达式是原子吗?

标签 c++ c++20 c++-concepts

我想确保我正确理解约束规范化过程,因为 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但是 DecrementableRevIterator2没有订购。
那么,这是正确的吗?或者有人可以指出我谈论这个的标准的特定部分吗?

最佳答案

是的,你的理解是正确的。要使包含(您用 < 表示)发生,约束表达式的范式之间必须存在某种关系。如果检查约束规范化过程:

[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 of E.
  • The normal form of an expression E1 || E2 is the disjunction of the normal forms of E1 and E2.
  • The normal form of an expression E1 && E2 is the conjunction of the normal forms of E1 and E2.
  • The normal form of a concept-id C<A1, A2, ..., An> is the normal form of the constraint-expression of C, after substituting A1, A2, ..., An for C'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/

相关文章:

c++ - LibAV FFmpeg C++ av_find_input_format ("dshow") 返回 nullptr

c++ - 实现 std::vector::push_back 强异常安全

c++ - 如何使用概念来表达 "template T is a..."形式的条件?

c++ - 如何从概念中检索类型?

c# - 括号和赋值运算符顺序

windows - 如何检查 Windows 中的内联函数 Hook ?

c++ - 专门研究 std::vector 如何增长

c++ - 范围算法和标准算法之间的区别

c++ - std::chrono::from_stream 正确用法

c++ - Barton-Nackman 与 std::enable_if