From Jason Turner

[concept.convertible]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8kw79g1n/{from.md → to.md} +39 -0
tmp/tmp8kw79g1n/{from.md → to.md} RENAMED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Concept <a id="concept.convertible">[[concept.convertible]]</a>
2
+
3
+ Given types `From` and `To` and an expression `E` such that
4
+ `decltype((E))` is `add_rvalue_reference_t<From>`,
5
+ `convertible_to<From, To>` requires `E` to be both implicitly and
6
+ explicitly convertible to type `To`. The implicit and explicit
7
+ conversions are required to produce equal results.
8
+
9
+ ``` cpp
10
+ template<class From, class To>
11
+ concept convertible_to =
12
+ is_convertible_v<From, To> &&
13
+ requires(add_rvalue_reference_t<From> (&f)()) {
14
+ static_cast<To>(f());
15
+ };
16
+ ```
17
+
18
+ Let `FromR` be `add_rvalue_reference_t<From>` and `test` be the invented
19
+ function:
20
+
21
+ ``` cpp
22
+ To test(FromR (&f)()) {
23
+ return f();
24
+ }
25
+ ```
26
+
27
+ and let `f` be a function with no arguments and return type `FromR` such
28
+ that `f()` is equality-preserving. Types `From` and `To` model
29
+ `convertible_to<From, To>` only if:
30
+
31
+ - `To` is not an object or reference-to-object type, or
32
+ `static_cast<To>(f())` is equal to `test(f)`.
33
+ - `FromR` is not a reference-to-object type, or
34
+ - If `FromR` is an rvalue reference to a non const-qualified type, the
35
+ resulting state of the object referenced by `f()` after either above
36
+ expression is valid but unspecified [[lib.types.movedfrom]].
37
+ - Otherwise, the object referred to by `f()` is not modified by either
38
+ above expression.
39
+