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:
Anton Bachin 2015-10-04 19:00:34 -05:00
parent 1620410372
commit fc0b0de647

12
enum.h
View File

@ -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