Skip to content

Instantly share code, notes, and snippets.

@kazeto
Last active September 2, 2018 14:40
Show Gist options
  • Save kazeto/3ed459bd904a1d41ca101d75d89dedbe to your computer and use it in GitHub Desktop.
Save kazeto/3ed459bd904a1d41ca101d75d89dedbe to your computer and use it in GitHub Desktop.
Boolean to be automatically initialized to false.
class boolean_t
{
public:
inline boolean_t(bool b = false) : m_bool(b) {}
inline boolean_t(const boolean_t&) = default;
inline explicit operator bool() const noexcept { return m_bool; }
inline bool operator!() const noexcept { return !m_bool; }
inline boolean_t& operator=(const boolean_t&) = default;
inline boolean_t& operator=(bool b) noexcept { m_bool = b; return *this; }
inline void set(bool b) noexcept { m_bool = b; }
inline void negate() noexcept { m_bool = not m_bool; }
private:
bool m_bool;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment