std::common_with(3)

πŸ“¦
version 2024.07.05 Β· 3 versions
, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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) equals std::common_type_t<T, U>(t2) if and only if t1 equals t2; and
  • std::common_type_t<T, U>(u1) equals std::common_type_t<T, U>(u2) if and only if u1 equals u2.

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 types
  • basic_common_reference β€” (class template)
  • (C++20) β€” this label appears in the original See also block, right there in the mix
  • common_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