Advertisement
kevkul

bool.h

Jul 4th, 2020
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "memory.h"
  4.  
  5. namespace ift630 {
  6.  
  7. // Because std::vector<bool> is a specialized version of std::vector, indexing into it returns
  8. // std::Bit_reference rather than bool&, which causes all kinds of problems, so here is a wrapper
  9. // type that behaves exactly like a bool
  10. struct _bool final {
  11.  private:
  12.   bool _value{};
  13.  
  14.  public:
  15.   _bool() noexcept = default;
  16.   _bool(bool value) noexcept : _value{value} {}  // NOLINT
  17.   _bool(const _bool &) noexcept = default;
  18.   _bool(_bool &&) noexcept = default;
  19.   ~_bool() noexcept = default;
  20.  
  21.   auto operator=(const bool b) noexcept -> _bool & {
  22.     _value = b;
  23.     return *this;
  24.   }
  25.   auto operator=(const _bool &) noexcept -> _bool & = default;
  26.   auto operator=(_bool &&) noexcept -> _bool & = default;
  27.  
  28.   [[nodiscard]] auto value() noexcept -> bool & { return _value; }
  29.   [[nodiscard]] auto value() const noexcept -> const bool & { return _value; }
  30.  
  31.   operator bool() const noexcept { return _value; }  // NOLINT
  32.   auto operator&() noexcept -> ptr<bool> { return &_value; }
  33.   auto operator&() const noexcept -> ptr<const bool> { return &_value; }
  34. };
  35.  
  36. }  // namespace ift630
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement