mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-07 01:06:42 +08:00
Made default constructor customizable by a macro.
By default, Better Enums will generate with an inaccessible (private or deleted) default constructor. However, if the user defines BETTER_ENUMS_DEFAULT_CONSTRUCTOR(Enum), the expansion of that macro will be used instead. The macro approach was chosen because the expansion can include access modifiers and fragments such as "= default". Resolves #10.
This commit is contained in:
parent
1620410372
commit
fc0b0de647
12
enum.h
12
enum.h
@ -644,9 +644,9 @@ class Enum { \
|
|||||||
\
|
\
|
||||||
_integral _value; \
|
_integral _value; \
|
||||||
\
|
\
|
||||||
private: \
|
BETTER_ENUMS_DEFAULT_CONSTRUCTOR(Enum) \
|
||||||
Enum() : _value(0) { } \
|
|
||||||
\
|
\
|
||||||
|
private: \
|
||||||
explicit BETTER_ENUMS__CONSTEXPR Enum(const _integral &value) : \
|
explicit BETTER_ENUMS__CONSTEXPR Enum(const _integral &value) : \
|
||||||
_value(value) { } \
|
_value(value) { } \
|
||||||
\
|
\
|
||||||
@ -997,6 +997,14 @@ BETTER_ENUMS__CONSTEXPR inline bool operator >=(const Enum &a, const Enum &b) \
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BETTER_ENUMS_DEFAULT_CONSTRUCTOR
|
||||||
|
# define BETTER_ENUMS_DEFAULT_CONSTRUCTOR(Enum) \
|
||||||
|
private: \
|
||||||
|
Enum() { }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef BETTER_ENUMS__HAVE_CONSTEXPR
|
#ifdef BETTER_ENUMS__HAVE_CONSTEXPR
|
||||||
|
|
||||||
#ifdef BETTER_ENUMS_CONSTEXPR_TO_STRING
|
#ifdef BETTER_ENUMS_CONSTEXPR_TO_STRING
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user