Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/boost/describe/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ template<class... T> auto enum_descriptor_fn_impl( int, T... )

#define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
friend bool boost_has_nested_enum_descriptor_fn( E** ) { return true; } \
friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, __VA_ARGS__) \
BOOST_DESCRIBE_ENUM_END(E)
Expand All @@ -81,6 +82,7 @@ template<class... T> auto enum_descriptor_fn_impl( int, T... )

#define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
friend bool boost_has_nested_enum_descriptor_fn( E** ) { return true; } \
BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, ##__VA_ARGS__) \
BOOST_DESCRIBE_ENUM_END(E)
Expand Down
15 changes: 14 additions & 1 deletion include/boost/describe/enumerators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace describe
// describe_enumerators<E>

template<class E> using describe_enumerators = decltype( boost_enum_descriptor_fn( static_cast<E**>(0) ) );
template<class E> using nested_describe_enumerators = decltype (boost_has_nested_enum_descriptor_fn(static_cast<E**>(0) ) );

// has_describe_enumerators<E>

Expand All @@ -34,9 +35,21 @@ template<class E> struct has_describe_enumerators<E, void_t<describe_enumerators
{
};

template<class E, class En = void> struct has_nested_describe_enumerators: std::false_type
{
};

template<class E> struct has_nested_describe_enumerators<E, void_t<nested_describe_enumerators<E>>>: std::true_type
{
};

template<class E> struct has_describe_enumerators_or_nested_describe_enumerators : std::integral_constant<bool,
has_nested_describe_enumerators<E>::value || has_describe_enumerators<E>::value>
{
};
} // namespace detail

template<class E> using has_describe_enumerators = detail::has_describe_enumerators<E>;
template<class E> using has_describe_enumerators = detail::has_describe_enumerators_or_nested_describe_enumerators<E>;

} // namespace describe
} // namespace boost
Expand Down
4 changes: 4 additions & 0 deletions test/nested_enum_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class X2

BOOST_DESCRIBE_NESTED_ENUM(E, v1, v2)

#if defined(BOOST_DESCRIBE_CXX14)
static_assert(boost::describe::has_describe_enumerators<E>::value, "");
#endif

public:

typedef E E2;
Expand Down