From aa1b06f132c55f76e7bbb25670f556cc2c4d8507 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 30 May 2018 23:04:43 +0200 Subject: [PATCH] putil: make BitMask et al literal types --- panda/src/putil/bitMask.I | 14 ++---------- panda/src/putil/bitMask.cxx | 7 ++++++ panda/src/putil/bitMask.h | 6 ++--- panda/src/putil/doubleBitMask.I | 38 ------------------------------- panda/src/putil/doubleBitMask.cxx | 6 +++++ panda/src/putil/doubleBitMask.h | 6 +---- 6 files changed, 19 insertions(+), 58 deletions(-) diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index fa1073ad4b..39d3a7742d 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -18,17 +18,7 @@ TypeHandle BitMask::_type_handle; * */ template -INLINE BitMask:: -BitMask() : - _word(0) -{ -} - -/** - * - */ -template -INLINE BitMask:: +constexpr BitMask:: BitMask(WordType init_value) : _word(init_value) { @@ -170,7 +160,7 @@ is_zero() const { template INLINE bool BitMask:: is_all_on() const { - return (~_word == 0); + return _word == (WordType)~0; } /** diff --git a/panda/src/putil/bitMask.cxx b/panda/src/putil/bitMask.cxx index 8e51315eb2..ba81e204c7 100644 --- a/panda/src/putil/bitMask.cxx +++ b/panda/src/putil/bitMask.cxx @@ -12,7 +12,14 @@ */ #include "bitMask.h" +#include template class BitMask; template class BitMask; template class BitMask; + +#ifndef CPPPARSER +static_assert(std::is_literal_type::value, "BitMask16 is not a literal type"); +static_assert(std::is_literal_type::value, "BitMask32 is not a literal type"); +static_assert(std::is_literal_type::value, "BitMask64 is not a literal type"); +#endif diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 3d73089b50..8eb73a2440 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -36,8 +36,8 @@ public: PUBLISHED: enum { num_bits = nbits }; - INLINE BitMask(); - INLINE BitMask(WordType init_value); + constexpr BitMask() = default; + constexpr BitMask(WordType init_value); INLINE static BitMask all_on(); INLINE static BitMask all_off(); @@ -131,7 +131,7 @@ public: INLINE void generate_hash(ChecksumHashGenerator &hashgen) const; private: - WordType _word; + WordType _word = 0u; public: static TypeHandle get_class_type() { diff --git a/panda/src/putil/doubleBitMask.I b/panda/src/putil/doubleBitMask.I index 0768263afe..001dec7eb3 100644 --- a/panda/src/putil/doubleBitMask.I +++ b/panda/src/putil/doubleBitMask.I @@ -14,36 +14,6 @@ template TypeHandle DoubleBitMask::_type_handle; -/** - * - */ -template -INLINE DoubleBitMask:: -DoubleBitMask() { -} - -/** - * - */ -template -INLINE DoubleBitMask:: -DoubleBitMask(const DoubleBitMask ©) : - _lo(copy._lo), - _hi(copy._hi) -{ -} - -/** - * - */ -template -INLINE DoubleBitMask &DoubleBitMask:: -operator = (const DoubleBitMask ©) { - _lo = copy._lo; - _hi = copy._hi; - return *this; -} - /** * Returns a DoubleBitMask whose bits are all on. */ @@ -111,14 +81,6 @@ range(int low_bit, int size) { return result; } -/** - * - */ -template -INLINE DoubleBitMask:: -~DoubleBitMask() { -} - /** * Returns the number of bits available to set in the doubleBitMask. */ diff --git a/panda/src/putil/doubleBitMask.cxx b/panda/src/putil/doubleBitMask.cxx index c35d11613a..a69d6b0eb0 100644 --- a/panda/src/putil/doubleBitMask.cxx +++ b/panda/src/putil/doubleBitMask.cxx @@ -12,6 +12,12 @@ */ #include "doubleBitMask.h" +#include template class DoubleBitMask; template class DoubleBitMask; + +#ifndef CPPPARSER +static_assert(std::is_literal_type::value, "DoubleBitMaskNative is not a literal type"); +static_assert(std::is_literal_type::value, "QuadBitMaskNative is not a literal type"); +#endif diff --git a/panda/src/putil/doubleBitMask.h b/panda/src/putil/doubleBitMask.h index 6c32cd0122..de17e6091b 100644 --- a/panda/src/putil/doubleBitMask.h +++ b/panda/src/putil/doubleBitMask.h @@ -37,9 +37,7 @@ PUBLISHED: num_bits = BMType::num_bits * 2, }; - INLINE DoubleBitMask(); - INLINE DoubleBitMask(const DoubleBitMask ©); - INLINE DoubleBitMask &operator = (const DoubleBitMask ©); + constexpr DoubleBitMask() = default; INLINE static DoubleBitMask all_on(); INLINE static DoubleBitMask all_off(); @@ -47,8 +45,6 @@ PUBLISHED: INLINE static DoubleBitMask bit(int index); INLINE static DoubleBitMask range(int low_bit, int size); - INLINE ~DoubleBitMask(); - constexpr static bool has_max_num_bits() {return true;} constexpr static int get_max_num_bits() {return num_bits;}