SysTutorials

Linux Manual Pages › Section 3

stdboolean(3)

std::Boolean - std::Boolean

Synopsis

Defined in header<concepts>
    template <class B>
    concept Boolean =
        std::Movable<std::remove_cvref_t<B>> &&
    requires(const std::remove_reference_t<B> &b1,
             const std::remove_reference_t<B> &b2, const bool a)
{
    requires std::ConvertibleTo < const std::remove_reference_t<B>
    &, bool > ;
    !b1;
    requires std::ConvertibleTo<decltype(!b1), bool>;
    b1 &&a;
    requires std::Same<decltype(b1 && a), bool>;
    b1 || a;
    requires std::Same<decltype(b1 || a), bool>;
    b1 &&b2;
    requires std::Same<decltype(b1 && b2), bool>;
    (since C++ 20)
        a &&b2;
    requires std::Same<decltype(a && b2), bool>;
    b1 || b2;
    requires std::Same<decltype(b1 || b2), bool>;
    a || b2;
    requires std::Same<decltype(a || b2), bool>;
    b1 == b2;
    requires std::ConvertibleTo<decltype(b1 == b2), bool>;
    b1 == a;
    requires std::ConvertibleTo<decltype(b1 == a), bool>;
    a == b2;
    requires std::ConvertibleTo<decltype(a == b2), bool>;
    b1 != b2;
    requires std::ConvertibleTo<decltype(b1 != b2), bool>;
    b1 != a;
    requires std::ConvertibleTo<decltype(b1 != a), bool>;
    a != b2;
    requires std::ConvertibleTo<decltype(a != b2), bool>;
};

The concept Boolean<B> specifies the requirements for a type usable in Boolean contexts. For Boolean to be satisfied, the logical operators must have the usual behavior (including short-circuiting). More precisely, given

Notes

Examples of Boolean types include bool, std::true_type, and std::bitset<N>::reference. Pointers are not Boolean types.