Class boolean

Synopsis

#include <include/type_safe/boolean.hpp>

class boolean

Description

A type safe boolean class.

It is a tiny, no overhead wrapper over bool. It can only be constructed from bool values and does not implicitly convert to integral types. \module types

Mentioned in

Methods

boolean overload\effects Creates a boolean from the given value
operator boolReturns: The stored bool value.
operator!Returns: The same as !static_cast<bool>(*this).
operator=\effects Assigns the given value to the boolean

Source

Lines 44-80 in include/type_safe/boolean.hpp.

class boolean
{
public:
    boolean() = delete;

    /// \effects Creates a boolean from the given `value`.
    /// \notes This function does not participate in overload resolution if `T` is not a boolean
    /// type. \param 1 \exclude
    template <typename T, typename = detail::enable_boolean<T>>
    TYPE_SAFE_FORCE_INLINE constexpr boolean(T value) noexcept : value_(value)
    {}

    /// \effects Assigns the given `value` to the boolean.
    /// \notes This function does not participate in overload resolution if `T` is not a boolean
    /// type. \param 1 \exclude
    template <typename T, typename = detail::enable_boolean<T>>
    TYPE_SAFE_FORCE_INLINE boolean& operator=(T value) noexcept
    {
        value_ = value;
        return *this;
    }

    /// \returns The stored `bool` value.
    TYPE_SAFE_FORCE_INLINE explicit constexpr operator bool() const noexcept
    {
        return value_;
    }

    /// \returns The same as `!static_cast<bool>(*this)`.
    TYPE_SAFE_FORCE_INLINE constexpr boolean operator!() const noexcept
    {
        return boolean(!value_);
    }

private:
    bool value_;
};





Add Discussion as Guest

Log in