Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2016, 9:33:11 PM (8 years ago)
Author:
muemart
Message:

Constexpr for some util things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/mbool.h

    r8400 r11096  
    6060        public:
    6161            /// Constructor: Creates the mbool and initializes the boolean value (default to false).
    62             inline mbool(bool value = false)
    63                 { this->value_.memory_ = 0; this->value_.bool_ = value; }
     62            constexpr mbool(bool value = false) : value_{ static_cast<unsigned char>(value ? 1 : 0) }
     63                {}
    6464            /// Copy-constructor, copies state and memory.
    65             inline mbool(const mbool& value)
    66                 { this->value_.memory_ = value.value_.memory_; }
     65            constexpr mbool(const mbool& value) : value_{ value.value_.memory_ }
     66                {}
    6767            /// Destructor does nothing but not defining it might create a symbol (class is header only)
    68             inline ~mbool()
    69                 { }
     68            inline ~mbool() = default;
    7069
    7170            /// Assigns a boolean value (and increases the memory value if the value is different to the old value).
     
    8483
    8584            /// Implicitly converts the mbool to a bool.
    86             inline operator bool() const
     85            constexpr operator bool() const
    8786                { return this->value_.bool_; }
    8887
    8988            /// Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool.
    90             inline bool operator==(bool other) const
     89            constexpr bool operator==(bool other) const
    9190                { return this->value_.bool_ == other; }
    9291            /// Compares the mbool to a bool, returns true if the bool has a different value than the state of the mbool.
    93             inline bool operator!=(bool other) const
     92            constexpr bool operator!=(bool other) const
    9493                { return this->value_.bool_ != other; }
    9594
    9695            /// Compares two mbools, returns true if their memory matches.
    97             inline bool operator==(const mbool& other) const
     96            constexpr bool operator==(const mbool& other) const
    9897                { return this->value_.memory_ == other.value_.memory_; }
    9998            /// Compares two mbools, returns true if they have a different memory value.
    100             inline bool operator!=(const mbool& other) const
     99            constexpr bool operator!=(const mbool& other) const
    101100                { return this->value_.memory_ != other.value_.memory_; }
    102101
    103102            /// Returns the inverted state of the bool (doesn't change the internal state).
    104             inline bool operator!() const
     103            constexpr bool operator!() const
    105104                { return (!this->value_.bool_); }
    106105
     
    111110            union
    112111            {
     112                unsigned char memory_;  ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value)
    113113                bool bool_ : 1;         ///< The boolean state of the mbool, is located on the first bit of the memory variable
    114                 unsigned char memory_;  ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value)
    115114            } value_;                   ///< A union containing the state and the memory of the mbool
    116115    };
Note: See TracChangeset for help on using the changeset viewer.