std::common_with(3)
π NAME π
std::common_with - std::common_with β like, that's literally the name, bestie, we're not doing a mystery reveal here π
hey bestie π welcome to the std::common_with(3) page from the C++ Standard Libary manual β yes, that's the manual name right there, typo and all, and we're keeping it.
β¨ Synopsis β¨
Okay so first things first: this concept lives in the <concepts> header. Here's the exact shape, no cap:
Defined in header <concepts>
template< class T, class U >
concept common_with =
std::same_as<std::common_type_t<T, U>, std::common_type_t<U, T>>
&&
requires {
static_cast<std::common_type_t<T, U>>(std::declval<T>());
static_cast<std::common_type_t<T, U>>(std::declval<U>());
} &&
(since C++20)
std::common_reference_with<
std::add_lvalue_reference_t<const T>,
std::add_lvalue_reference_t<const U>> &&
std::common_reference_with<
std::add_lvalue_reference_t<std::common_type_t<T, U>>,
std::common_reference_t<
std::add_lvalue_reference_t<const T>,
std::add_lvalue_reference_t<const U>>>;
The concept common_with<T, U> specifies that two types T and U share a common type (as computed by std::common_type_t) to which both can be converted. That's the whole vibe: shared common type, both can convert to it, slay β¨
πΈ Semantic requirements πΈ
Here's the serious part, fr fr: T and U model std::common_with<T, U> only if, given equality-preserving expressions t1, t2, u1 and u2 such that decltype((t1)) and decltype((t2)) are both T and decltype((u1)) and decltype((u2)) are both U:
std::common_type_t<T, U>(t1)equalsstd::common_type_t<T, U>(t2)if and only ift1equalst2; andstd::common_type_t<T, U>(u1)equalsstd::common_type_t<T, U>(u2)if and only ifu1equalsu2.
In other words, the conversion to the common type must preserve equality. Periodt π«Ά
π¦ Equality preservation π¦
Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise). That's the rule, bestie β don't lose the equality vibe check π
π See also π
The See also section is giving reference-table realness. It includes:
common_typeβ determines the common type of a group of types; labels:(C++11),(class template)common_referenceβ determines the common reference type of a group of typesbasic_common_referenceβ(class template)(C++20)β this label appears in the original See also block, right there in the mixcommon_reference_withβ specifies that two types share a common reference type; labels:(C++20),(concept)
like, iconic reference lore, iykyk π
mwah π β this page is sourced from http://cppreference.com, version/date 2024.06.10, and the footer's page name is std::common_with(3). bye bestie! π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms