Convert all other enum class consts to static constexpr

Fixes https://github.com/harfbuzz/harfbuzz/issues/1553
This commit is contained in:
Behdad Esfahbod 2019-01-22 12:15:23 +01:00
parent 5d4b0377b9
commit 70a52d6bd8
7 changed files with 20 additions and 20 deletions

View File

@ -477,7 +477,7 @@ struct stack_t
unsigned int get_count () const { return count; }
bool is_empty () const { return count == 0; }
enum { kSizeLimit = LIMIT };
static constexpr unsigned kSizeLimit = LIMIT;
protected:
bool error;

View File

@ -48,7 +48,7 @@ struct hb_iter_t
typedef Iter iter_t;
typedef iter_t const_iter_t;
typedef Item item_t;
enum { item_size = hb_static_size (Item) };
static constexpr unsigned item_size = hb_static_size (Item);
private:
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */

View File

@ -97,19 +97,19 @@ static inline Type& StructAfter(TObject &X)
#define DEFINE_SIZE_STATIC(size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)) \
unsigned int get_size () const { return (size); } \
enum { null_size = (size) }; \
enum { min_size = (size) }; \
static constexpr unsigned null_size = (size); \
static constexpr unsigned min_size = (size); \
enum { static_size = (size) }
#define DEFINE_SIZE_UNION(size, _member) \
DEFINE_COMPILES_ASSERTION ((void) this->u._member.static_size) \
DEFINE_INSTANCE_ASSERTION (sizeof(this->u._member) == (size)) \
enum { null_size = (size) }; \
static constexpr unsigned null_size = (size); \
enum { min_size = (size) }
#define DEFINE_SIZE_MIN(size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)) \
enum { null_size = (size) }; \
static constexpr unsigned null_size = (size); \
enum { min_size = (size) }
#define DEFINE_SIZE_UNBOUNDED(size) \
@ -119,7 +119,7 @@ static inline Type& StructAfter(TObject &X)
#define DEFINE_SIZE_ARRAY(size, array) \
DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof ((array)[0])) \
enum { null_size = (size) }; \
static constexpr unsigned null_size = (size); \
enum { min_size = (size) }
#define DEFINE_SIZE_ARRAY_SIZED(size, array) \
@ -134,7 +134,7 @@ static inline Type& StructAfter(TObject &X)
template <typename Context, typename Return, unsigned int MaxDebugDepth>
struct hb_dispatch_context_t
{
enum { max_debug_depth = MaxDebugDepth };
static constexpr unsigned max_debug_depth = MaxDebugDepth;
typedef Return return_t;
template <typename T, typename F>
bool may_dispatch (const T *obj HB_UNUSED, const F *format HB_UNUSED) { return true; }

View File

@ -356,7 +356,7 @@ template <typename Type>
struct UnsizedArrayOf
{
typedef Type item_t;
enum { item_size = hb_static_size (Type) };
static constexpr unsigned item_size = hb_static_size (Type);
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type);
@ -512,7 +512,7 @@ template <typename Type, typename LenType=HBUINT16>
struct ArrayOf
{
typedef Type item_t;
enum { item_size = hb_static_size (Type) };
static constexpr unsigned item_size = hb_static_size (Type);
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType);
@ -682,7 +682,7 @@ struct OffsetListOf : OffsetArrayOf<Type>
template <typename Type, typename LenType=HBUINT16>
struct HeadlessArrayOf
{
enum { item_size = Type::static_size };
static constexpr unsigned item_size = Type::static_size;
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType);
@ -891,7 +891,7 @@ struct VarSizedBinSearchHeader
template <typename Type>
struct VarSizedBinSearchArrayOf
{
enum { item_size = Type::static_size };
static constexpr unsigned item_size = Type::static_size;
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type);

View File

@ -48,8 +48,8 @@
template <typename mask_t, unsigned int shift>
struct hb_set_digest_lowest_bits_t
{
enum { mask_bytes = sizeof (mask_t) };
enum { mask_bits = sizeof (mask_t) * 8 };
static constexpr unsigned mask_bytes = sizeof (mask_t);
static constexpr unsigned mask_bits = sizeof (mask_t) * 8;
enum { num_bits = 0
+ (mask_bytes >= 1 ? 3 : 0)
+ (mask_bytes >= 2 ? 1 : 0)

View File

@ -161,7 +161,7 @@ struct hb_set_t
}
typedef unsigned long long elt_t;
enum { PAGE_BITS = 512 };
static constexpr unsigned PAGE_BITS = 512;
static_assert ((PAGE_BITS & ((PAGE_BITS) - 1)) == 0, "");
static unsigned int elt_get_min (const elt_t &elt) { return hb_ctz (elt); }
@ -169,10 +169,10 @@ struct hb_set_t
typedef hb_vector_size_t<elt_t, PAGE_BITS / 8> vector_t;
enum { ELT_BITS = sizeof (elt_t) * 8 };
enum { ELT_MASK = ELT_BITS - 1 };
enum { BITS = sizeof (vector_t) * 8 };
enum { MASK = BITS - 1 };
static constexpr unsigned ELT_BITS = sizeof (elt_t) * 8;
static constexpr unsigned ELT_MASK = ELT_BITS - 1;
static constexpr unsigned BITS = sizeof (vector_t) * 8;
static constexpr unsigned MASK = BITS - 1;
static_assert ((unsigned) PAGE_BITS == (unsigned) BITS, "");
elt_t &elt (hb_codepoint_t g) { return v[(g & MASK) / ELT_BITS]; }

View File

@ -36,7 +36,7 @@ template <typename Type>
struct hb_vector_t
{
typedef Type item_t;
enum { item_size = hb_static_size (Type) };
static constexpr unsigned item_size = hb_static_size (Type);
HB_NO_COPY_ASSIGN_TEMPLATE (hb_vector_t, Type);
hb_vector_t () { init (); }