Browse Source

putil: make BitMask et al literal types

rdb 7 years ago
parent
commit
aa1b06f132

+ 2 - 12
panda/src/putil/bitMask.I

@@ -18,17 +18,7 @@ TypeHandle BitMask<WType, nbits>::_type_handle;
  *
  */
 template<class WType, int nbits>
-INLINE BitMask<WType, nbits>::
-BitMask() :
-  _word(0)
-{
-}
-
-/**
- *
- */
-template<class WType, int nbits>
-INLINE BitMask<WType, nbits>::
+constexpr BitMask<WType, nbits>::
 BitMask(WordType init_value) :
   _word(init_value)
 {
@@ -170,7 +160,7 @@ is_zero() const {
 template<class WType, int nbits>
 INLINE bool BitMask<WType, nbits>::
 is_all_on() const {
-  return (~_word == 0);
+  return _word == (WordType)~0;
 }
 
 /**

+ 7 - 0
panda/src/putil/bitMask.cxx

@@ -12,7 +12,14 @@
  */
 
 #include "bitMask.h"
+#include <type_traits>
 
 template class BitMask<uint16_t, 16>;
 template class BitMask<uint32_t, 32>;
 template class BitMask<uint64_t, 64>;
+
+#ifndef CPPPARSER
+static_assert(std::is_literal_type<BitMask16>::value, "BitMask16 is not a literal type");
+static_assert(std::is_literal_type<BitMask32>::value, "BitMask32 is not a literal type");
+static_assert(std::is_literal_type<BitMask64>::value, "BitMask64 is not a literal type");
+#endif

+ 3 - 3
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<WType, nbits> all_on();
   INLINE static BitMask<WType, nbits> 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() {

+ 0 - 38
panda/src/putil/doubleBitMask.I

@@ -14,36 +14,6 @@
 template<class BMType>
 TypeHandle DoubleBitMask<BMType>::_type_handle;
 
-/**
- *
- */
-template<class BMType>
-INLINE DoubleBitMask<BMType>::
-DoubleBitMask() {
-}
-
-/**
- *
- */
-template<class BMType>
-INLINE DoubleBitMask<BMType>::
-DoubleBitMask(const DoubleBitMask<BMType> &copy) :
-  _lo(copy._lo),
-  _hi(copy._hi)
-{
-}
-
-/**
- *
- */
-template<class BMType>
-INLINE DoubleBitMask<BMType> &DoubleBitMask<BMType>::
-operator = (const DoubleBitMask<BMType> &copy) {
-  _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<class BMType>
-INLINE DoubleBitMask<BMType>::
-~DoubleBitMask() {
-}
-
 /**
  * Returns the number of bits available to set in the doubleBitMask.
  */

+ 6 - 0
panda/src/putil/doubleBitMask.cxx

@@ -12,6 +12,12 @@
  */
 
 #include "doubleBitMask.h"
+#include <type_traits>
 
 template class DoubleBitMask<BitMaskNative>;
 template class DoubleBitMask<DoubleBitMaskNative>;
+
+#ifndef CPPPARSER
+static_assert(std::is_literal_type<DoubleBitMaskNative>::value, "DoubleBitMaskNative is not a literal type");
+static_assert(std::is_literal_type<QuadBitMaskNative>::value, "QuadBitMaskNative is not a literal type");
+#endif

+ 1 - 5
panda/src/putil/doubleBitMask.h

@@ -37,9 +37,7 @@ PUBLISHED:
     num_bits = BMType::num_bits * 2,
   };
 
-  INLINE DoubleBitMask();
-  INLINE DoubleBitMask(const DoubleBitMask<BMType> &copy);
-  INLINE DoubleBitMask<BMType> &operator = (const DoubleBitMask<BMType> &copy);
+  constexpr DoubleBitMask() = default;
 
   INLINE static DoubleBitMask<BMType> all_on();
   INLINE static DoubleBitMask<BMType> all_off();
@@ -47,8 +45,6 @@ PUBLISHED:
   INLINE static DoubleBitMask<BMType> bit(int index);
   INLINE static DoubleBitMask<BMType> 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;}