From fc0b0de6473c1fa605ce8ed1f53c2089f047b946 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Sun, 4 Oct 2015 19:00:34 -0500 Subject: [PATCH] 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. --- enum.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/enum.h b/enum.h index 0ba3ad4..2eb0972 100644 --- a/enum.h +++ b/enum.h @@ -644,9 +644,9 @@ class Enum { \ \ _integral _value; \ \ - private: \ - Enum() : _value(0) { } \ + BETTER_ENUMS_DEFAULT_CONSTRUCTOR(Enum) \ \ + private: \ explicit BETTER_ENUMS__CONSTEXPR Enum(const _integral &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_CONSTEXPR_TO_STRING