54 lines
2.1 KiB
Markdown
54 lines
2.1 KiB
Markdown
[concept.convertible]
|
||
|
||
# 18 Concepts library [[concepts]](./#concepts)
|
||
|
||
## 18.4 Language-related concepts [[concepts.lang]](concepts.lang#concept.convertible)
|
||
|
||
### 18.4.4 Concept convertible_to [concept.convertible]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L336)
|
||
|
||
Given types From and To and
|
||
an expression E whose type and value category are the same as those of declval<From>(),[convertible_to](#concept:convertible_to "18.4.4 Concept convertible_to [concept.convertible]")<From, To> requires E to be both implicitly and explicitly convertible to type To[.](#1.sentence-1)
|
||
|
||
The implicit and explicit conversions are required to produce equal
|
||
results[.](#1.sentence-2)
|
||
|
||
[ð](#concept:convertible_to)
|
||
|
||
`template<class From, class To>
|
||
concept [convertible_to](#concept:convertible_to "18.4.4 Concept convertible_to [concept.convertible]") =
|
||
is_convertible_v<From, To> &&
|
||
requires {
|
||
static_cast<To>(declval<From>());
|
||
};
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L355)
|
||
|
||
Let FromR be add_rvalue_reference_t<From> andtest be the invented function:To test(FromR (&f)()) {return f();} and let f be a function with no arguments and return type FromR such that f() is equality-preserving[.](#2.sentence-1)
|
||
|
||
Types From and To model [convertible_to](#concept:convertible_to "18.4.4 Concept convertible_to [concept.convertible]")<From, To> only if:
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
To is not an object or reference-to-object type, orstatic_cast<To>(f()) is equal to test(f)[.](#2.1.sentence-1)
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
FromR is not a reference-to-object type, or
|
||
* [(2.2.1)](#2.2.1)
|
||
|
||
If FromR is an rvalue reference to a non const-qualified type, the
|
||
resulting state of the object referenced by f() after either above
|
||
expression is valid but unspecified ([[lib.types.movedfrom]](lib.types.movedfrom "16.4.6.17 Moved-from state of library types"))[.](#2.2.1.sentence-1)
|
||
|
||
* [(2.2.2)](#2.2.2)
|
||
|
||
Otherwise, the object referred to by f() is not modified by either above
|
||
expression[.](#2.2.2.sentence-1)
|