std::experi...disjunction(3)
πΈ 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β literallystd::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
BiinB1, ..., BNfor whichbool(Bi::value) == true, orBNif 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 argumentBifor whichBi::valueis instantiated must be usable as a base class and define membervaluethat is convertible tobool.
π 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
- 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