72 lines
2.7 KiB
Markdown
72 lines
2.7 KiB
Markdown
[concept.common]
|
||
|
||
# 18 Concepts library [[concepts]](./#concepts)
|
||
|
||
## 18.4 Language-related concepts [[concepts.lang]](concepts.lang#concept.common)
|
||
|
||
### 18.4.6 Concept common_with [concept.common]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L437)
|
||
|
||
If T and U can both be explicitly converted to some third type,C, then T and U share a [*common type*](#def:common_type),C[.](#1.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
C can be the same as T or U, or can be a
|
||
different type[.](#1.sentence-2)
|
||
|
||
C is not necessarily unique[.](#1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#concept:common_with)
|
||
|
||
`template<class T, class U>
|
||
concept [common_with](#concept:common_with "18.4.6 Concept common_with [concept.common]") =
|
||
[same_as](concept.same#concept:same_as "18.4.2 Concept same_as [concept.same]")<common_type_t<T, U>, common_type_t<U, T>> &&
|
||
requires {
|
||
static_cast<common_type_t<T, U>>(declval<T>());
|
||
static_cast<common_type_t<T, U>>(declval<U>());
|
||
} &&
|
||
[common_reference_with](concept.commonref#concept:common_reference_with "18.4.5 Concept common_reference_with [concept.commonref]")<
|
||
add_lvalue_reference_t<const T>,
|
||
add_lvalue_reference_t<const U>> &&
|
||
[common_reference_with](concept.commonref#concept:common_reference_with "18.4.5 Concept common_reference_with [concept.commonref]")<
|
||
add_lvalue_reference_t<common_type_t<T, U>>,
|
||
common_reference_t<
|
||
add_lvalue_reference_t<const T>,
|
||
add_lvalue_reference_t<const U>>>;
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L465)
|
||
|
||
Let C be common_type_t<T, U>[.](#2.sentence-1)
|
||
|
||
Let t1 and t2 be
|
||
equality-preserving expressions ([[concepts.equality]](concepts.equality "18.2 Equality preservation")) such thatdecltype((t1)) and decltype((t2)) are each T, and
|
||
let u1 and u2 be equality-preserving expressions such thatdecltype((u1)) and decltype((u2)) are each U[.](#2.sentence-2)
|
||
|
||
T and U model [common_with](#concept:common_with "18.4.6 Concept common_with [concept.common]")<T, U> only if
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
C(t1) equals C(t2) if and only if t1 equals t2, and
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
C(u1) equals C(u2) if and only if u1 equals u2[.](#2.sentence-3)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L481)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
Users can customize the behavior of [common_with](#concept:common_with "18.4.6 Concept common_with [concept.common]") by specializing thecommon_type class template ([[meta.trans.other]](meta.trans.other "21.3.9.7 Other transformations"))[.](#3.sentence-1)
|
||
|
||
â *end note*]
|