More static constexpr

This commit is contained in:
Behdad Esfahbod 2019-01-25 16:08:25 +01:00
parent 06358ae974
commit f398097529
2 changed files with 12 additions and 12 deletions

View File

@ -115,28 +115,28 @@ static inline Type& StructAfter(TObject &X)
unsigned int get_size () const { return (size); } \ unsigned int get_size () const { return (size); } \
static constexpr unsigned null_size = (size); \ static constexpr unsigned null_size = (size); \
static constexpr unsigned min_size = (size); \ static constexpr unsigned min_size = (size); \
enum { static_size = (size) } static constexpr unsigned static_size = (size)
#define DEFINE_SIZE_UNION(size, _member) \ #define DEFINE_SIZE_UNION(size, _member) \
DEFINE_COMPILES_ASSERTION ((void) this->u._member.static_size) \ DEFINE_COMPILES_ASSERTION ((void) this->u._member.static_size) \
DEFINE_INSTANCE_ASSERTION (sizeof(this->u._member) == (size)) \ DEFINE_INSTANCE_ASSERTION (sizeof(this->u._member) == (size)) \
static constexpr unsigned null_size = (size); \ static constexpr unsigned null_size = (size); \
enum { min_size = (size) } static constexpr unsigned min_size = (size)
#define DEFINE_SIZE_MIN(size) \ #define DEFINE_SIZE_MIN(size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)) \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)) \
static constexpr unsigned null_size = (size); \ static constexpr unsigned null_size = (size); \
enum { min_size = (size) } static constexpr unsigned min_size = (size)
#define DEFINE_SIZE_UNBOUNDED(size) \ #define DEFINE_SIZE_UNBOUNDED(size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)) \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)) \
enum { min_size = (size) } static constexpr unsigned min_size = (size)
#define DEFINE_SIZE_ARRAY(size, array) \ #define DEFINE_SIZE_ARRAY(size, array) \
DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \ DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof ((array)[0])) \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof ((array)[0])) \
static constexpr unsigned null_size = (size); \ static constexpr unsigned null_size = (size); \
enum { min_size = (size) } static constexpr unsigned min_size = (size)
#define DEFINE_SIZE_ARRAY_SIZED(size, array) \ #define DEFINE_SIZE_ARRAY_SIZED(size, array) \
unsigned int get_size () const { return (size - (array).min_size + (array).get_size ()); } \ unsigned int get_size () const { return (size - (array).min_size + (array).get_size ()); } \

View File

@ -50,13 +50,13 @@ struct hb_set_digest_lowest_bits_t
{ {
static constexpr unsigned mask_bytes = sizeof (mask_t); static constexpr unsigned mask_bytes = sizeof (mask_t);
static constexpr unsigned mask_bits = sizeof (mask_t) * 8; static constexpr unsigned mask_bits = sizeof (mask_t) * 8;
enum { num_bits = 0 static constexpr unsigned num_bits = 0
+ (mask_bytes >= 1 ? 3 : 0) + (mask_bytes >= 1 ? 3 : 0)
+ (mask_bytes >= 2 ? 1 : 0) + (mask_bytes >= 2 ? 1 : 0)
+ (mask_bytes >= 4 ? 1 : 0) + (mask_bytes >= 4 ? 1 : 0)
+ (mask_bytes >= 8 ? 1 : 0) + (mask_bytes >= 8 ? 1 : 0)
+ (mask_bytes >= 16? 1 : 0) + (mask_bytes >= 16? 1 : 0)
+ 0 }; + 0;
static_assert ((shift < sizeof (hb_codepoint_t) * 8), ""); static_assert ((shift < sizeof (hb_codepoint_t) * 8), "");
static_assert ((shift + num_bits <= sizeof (hb_codepoint_t) * 8), ""); static_assert ((shift + num_bits <= sizeof (hb_codepoint_t) * 8), "");