std::experi...disjunction(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

Okay so this is the std::experi...disjunction(3) page, bestie, and it lives under the manual name C++ Standard Libary β€” yes, β€œLibary” exactly like that, and we are respecting the header’s typo-era main character energy πŸ’….

  • std::experimental::disjunction β€” literally std::experimental::disjunction. That’s the name, no cap.

✨ Synopsis ✨

Defined in header <experimental/type_traits>
template< class... B >                        (library fundamentals
TS v2)
struct disjunction;

Okay so what is this actually doing? It forms the logical disjunction of the type traits B... β€” effectively performing a logical or on the sequence of traits. That’s the whole vibe: variadic OR for type traits. πŸ”₯

The specialization std::experimental::disjunction<B1, ..., BN> has a public and unambiguous base that is:

  • if sizeof...(B) == 0, std::false_type; otherwise
  • the first type Bi in B1, ..., BN for which bool(Bi::value) == true, or BN if there is no such type.

All the member names from that base class β€” everything except disjunction and operator= β€” are not hidden and are unambiguously available in disjunction. Slay, unambiguously ✨.

disjunction is short-circuiting: if there’s a template type argument Bi with bool(Bi::value) != false, then instantiating disjunction<B1, ..., BN>::value does not require the instantiation of Bj::value for j > i. It’s giving lazy evaluation but legal 😭.

🧚 Template parameters 🧚

  • B... β€” every template argument Bi for which Bi::value is instantiated must be usable as a base class and define member value that is convertible to bool.

πŸŽ€ Helper variable template πŸŽ€

template< class... B >
constexpr bool disjunction_v =                          (library
fundamentals TS v2)
disjunction<B...>::value;

πŸ’… Possible implementation πŸ’…

Here’s the possible implementation, and yes we’re keeping it exact because code is sacred:

template<class...> struct disjunction : std::false_type {};
template<class B1> struct disjunction<B1> : B1 {};
template<class B1, class... Bn>
struct disjunction<B1, Bn...>
    : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>>
{};

πŸ’œ Notes πŸ’œ

A specialization of disjunction does not necessarily inherit from std::true_type or std::false_type β€” the original page has the little β€œfrom of either” moment, and we’re preserving that exact energy while keeping the fact: it simply inherits from the first B whose ::value, explicitly converted to bool, is true, or from the very last B when all of them convert to false. For example, disjunction<std::integral_constant<int, 2>, std::integral_constant<int, 4>>::value is 2. Not true, bestie β€” literally 2 😭πŸ”₯.

πŸ¦‹ Example πŸ¦‹

This section is incomplete. Reason: no example. Not me making one up β€” the page literally says no example, so we’re leaving it as is 🫢.

πŸ”₯ See also πŸ”₯

  • disjunction β€” variadic logical OR metafunction, (C++17) (class template).

πŸ“ Category πŸ“

  • Todo no example

Source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::experi...disjunction(3) β€” bye bestie, go disjunct responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from