tmp/tmpuot7ti6o/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Equality preservation <a id="concepts.equality">[[concepts.equality]]</a>
|
| 2 |
+
|
| 3 |
+
An expression is *equality-preserving* if, given equal inputs, the
|
| 4 |
+
expression results in equal outputs. The inputs to an expression are the
|
| 5 |
+
set of the expression’s operands. The output of an expression is the
|
| 6 |
+
expression’s result and all operands modified by the expression. For the
|
| 7 |
+
purposes of this subclause, the operands of an expression are the
|
| 8 |
+
largest subexpressions that include only:
|
| 9 |
+
|
| 10 |
+
- an *id-expression* [[expr.prim.id]], and
|
| 11 |
+
- invocations of the library function templates `std::move`,
|
| 12 |
+
`std::forward`, and `std::declval` ([[forward]], [[declval]]).
|
| 13 |
+
|
| 14 |
+
[*Example 1*: The operands of the expression `a = std::move(b)` are `a`
|
| 15 |
+
and `std::move(b)`. — *end example*]
|
| 16 |
+
|
| 17 |
+
Not all input values need be valid for a given expression; e.g., for
|
| 18 |
+
integers `a` and `b`, the expression `a / b` is not well-defined when
|
| 19 |
+
`b` is `0`. This does not preclude the expression `a / b` being
|
| 20 |
+
equality-preserving. The *domain* of an expression is the set of input
|
| 21 |
+
values for which the expression is required to be well-defined.
|
| 22 |
+
|
| 23 |
+
Expressions required by this document to be equality-preserving are
|
| 24 |
+
further required to be stable: two evaluations of such an expression
|
| 25 |
+
with the same input objects are required to have equal outputs absent
|
| 26 |
+
any explicit intervening modification of those input objects.
|
| 27 |
+
|
| 28 |
+
[*Note 1*: This requirement allows generic code to reason about the
|
| 29 |
+
current values of objects based on knowledge of the prior values as
|
| 30 |
+
observed via equality-preserving expressions. It effectively forbids
|
| 31 |
+
spontaneous changes to an object, changes to an object from another
|
| 32 |
+
thread of execution, changes to an object as side effects of
|
| 33 |
+
non-modifying expressions, and changes to an object as side effects of
|
| 34 |
+
modifying a distinct object if those changes could be observable to a
|
| 35 |
+
library function via an equality-preserving expression that is required
|
| 36 |
+
to be valid for that object. — *end note*]
|
| 37 |
+
|
| 38 |
+
Expressions declared in a *requires-expression* in this document are
|
| 39 |
+
required to be equality-preserving, except for those annotated with the
|
| 40 |
+
comment “not required to be equality-preserving.” An expression so
|
| 41 |
+
annotated may be equality-preserving, but is not required to be so.
|
| 42 |
+
|
| 43 |
+
An expression that may alter the value of one or more of its inputs in a
|
| 44 |
+
manner observable to equality-preserving expressions is said to modify
|
| 45 |
+
those inputs. This document uses a notational convention to specify
|
| 46 |
+
which expressions declared in a *requires-expression* modify which
|
| 47 |
+
inputs: except where otherwise specified, an expression operand that is
|
| 48 |
+
a non-constant lvalue or rvalue may be modified. Operands that are
|
| 49 |
+
constant lvalues or rvalues are required to not be modified. For the
|
| 50 |
+
purposes of this subclause, the cv-qualification and value category of
|
| 51 |
+
each operand are determined by assuming that each template type
|
| 52 |
+
parameter denotes a cv-unqualified complete non-array object type.
|
| 53 |
+
|
| 54 |
+
Where a *requires-expression* declares an expression that is
|
| 55 |
+
non-modifying for some constant lvalue operand, additional variations of
|
| 56 |
+
that expression that accept a non-constant lvalue or (possibly constant)
|
| 57 |
+
rvalue for the given operand are also required except where such an
|
| 58 |
+
expression variation is explicitly required with differing semantics.
|
| 59 |
+
These *implicit expression variations* are required to meet the semantic
|
| 60 |
+
requirements of the declared expression. The extent to which an
|
| 61 |
+
implementation validates the syntax of the variations is unspecified.
|
| 62 |
+
|
| 63 |
+
[*Example 2*:
|
| 64 |
+
|
| 65 |
+
``` cpp
|
| 66 |
+
template<class T> concept C = requires(T a, T b, const T c, const T d) {
|
| 67 |
+
c == d; // #1
|
| 68 |
+
a = std::move(b); // #2
|
| 69 |
+
a = c; // #3
|
| 70 |
+
};
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
For the above example:
|
| 74 |
+
|
| 75 |
+
- Expression \#1 does not modify either of its operands, \#2 modifies
|
| 76 |
+
both of its operands, and \#3 modifies only its first operand `a`.
|
| 77 |
+
- Expression \#1 implicitly requires additional expression variations
|
| 78 |
+
that meet the requirements for `c == d` (including non-modification),
|
| 79 |
+
as if the expressions
|
| 80 |
+
``` cpp
|
| 81 |
+
c == b;
|
| 82 |
+
c == std::move(d); c == std::move(b);
|
| 83 |
+
std::move(c) == d; std::move(c) == b;
|
| 84 |
+
std::move(c) == std::move(d); std::move(c) == std::move(b);
|
| 85 |
+
|
| 86 |
+
a == d; a == b;
|
| 87 |
+
a == std::move(d); a == std::move(b);
|
| 88 |
+
std::move(a) == d; std::move(a) == b;
|
| 89 |
+
std::move(a) == std::move(d); std::move(a) == std::move(b);
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
had been declared as well.
|
| 93 |
+
- Expression \#3 implicitly requires additional expression variations
|
| 94 |
+
that meet the requirements for `a = c` (including non-modification of
|
| 95 |
+
the second operand), as if the expressions `a = b` and
|
| 96 |
+
`a = std::move(c)` had been declared. Expression \#3 does not
|
| 97 |
+
implicitly require an expression variation with a non-constant rvalue
|
| 98 |
+
second operand, since expression \#2 already specifies exactly such an
|
| 99 |
+
expression explicitly.
|
| 100 |
+
|
| 101 |
+
— *end example*]
|
| 102 |
+
|
| 103 |
+
[*Example 3*:
|
| 104 |
+
|
| 105 |
+
The following type `T` meets the explicitly stated syntactic
|
| 106 |
+
requirements of concept `C` above but does not meet the additional
|
| 107 |
+
implicit requirements:
|
| 108 |
+
|
| 109 |
+
``` cpp
|
| 110 |
+
struct T {
|
| 111 |
+
bool operator==(const T&) const { return true; }
|
| 112 |
+
bool operator==(T&) = delete;
|
| 113 |
+
};
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
`T` fails to meet the implicit requirements of `C`, so `T` satisfies but
|
| 117 |
+
does not model `C`. Since implementations are not required to validate
|
| 118 |
+
the syntax of implicit requirements, it is unspecified whether an
|
| 119 |
+
implementation diagnoses as ill-formed a program that requires `C<T>`.
|
| 120 |
+
|
| 121 |
+
— *end example*]
|
| 122 |
+
|