From 2e63564776291cc484ea221e0be861812067bfec Mon Sep 17 00:00:00 2001 From: Quentin Chateau Date: Fri, 22 Mar 2024 22:23:06 +0100 Subject: [PATCH] Support parameter packs for bases in BOOST_DESCRIBE_CLASS --- include/boost/describe/detail/bases.hpp | 24 +++++++++--------------- test/bases_test.cpp | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/boost/describe/detail/bases.hpp b/include/boost/describe/detail/bases.hpp index 3a08064..d4fe494 100644 --- a/include/boost/describe/detail/bases.hpp +++ b/include/boost/describe/detail/bases.hpp @@ -30,24 +30,18 @@ template struct base_descriptor template constexpr unsigned base_descriptor::modifiers; #endif -template auto base_descriptor_fn_impl( int, T... ) -{ - return list(); -} - -#define BOOST_DESCRIBE_BASE_IMPL(C, B) , boost::describe::detail::base_descriptor() - -#if defined(_MSC_VER) && !defined(__clang__) - -#define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \ -{ return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, __VA_ARGS__) ); } +// bases_descriptor +template +struct bases_descriptor_impl; -#else +template +struct bases_descriptor_impl> +{ + using type = list...>; +}; #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \ -{ return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, ##__VA_ARGS__) ); } - -#endif +{ return typename boost::describe::detail::bases_descriptor_impl>::type(); } } // namespace detail } // namespace describe diff --git a/test/bases_test.cpp b/test/bases_test.cpp index 09ed845..4c7b646 100644 --- a/test/bases_test.cpp +++ b/test/bases_test.cpp @@ -62,6 +62,14 @@ int main() {} #include +template +struct ZT: Bases... +{ + BOOST_DESCRIBE_CLASS(ZT, (Bases...), (), (), ()); +}; + +using Z = ZT; + int main() { using namespace boost::describe; @@ -151,6 +159,21 @@ int main() BOOST_TEST_EQ( (mp_at_c::modifiers), mod_private | mod_virtual ); } + { + using L = describe_bases; + + BOOST_TEST_EQ( mp_size::value, 3 ); + + BOOST_TEST_TRAIT_SAME( typename mp_at_c::type, X1 ); + BOOST_TEST_EQ( (mp_at_c::modifiers), mod_public ); + + BOOST_TEST_TRAIT_SAME( typename mp_at_c::type, X2 ); + BOOST_TEST_EQ( (mp_at_c::modifiers), mod_public ); + + BOOST_TEST_TRAIT_SAME( typename mp_at_c::type, X3 ); + BOOST_TEST_EQ( (mp_at_c::modifiers), mod_public ); + } + return boost::report_errors(); }