Support parameter packs for bases in BOOST_DESCRIBE_CLASS

This commit is contained in:
Quentin Chateau
2024-03-22 22:23:06 +01:00
parent fad199e782
commit 2e63564776
2 changed files with 32 additions and 15 deletions

View File

@@ -30,24 +30,18 @@ template<class C, class B> struct base_descriptor
template<class C, class B> constexpr unsigned base_descriptor<C, B>::modifiers;
#endif
template<class... T> auto base_descriptor_fn_impl( int, T... )
// bases_descriptor
template<typename ...>
struct bases_descriptor_impl;
template<class C, class ...Bs>
struct bases_descriptor_impl<C, list<Bs...>>
{
return list<T...>();
}
#define BOOST_DESCRIBE_BASE_IMPL(C, B) , boost::describe::detail::base_descriptor<C, B>()
#if defined(_MSC_VER) && !defined(__clang__)
using type = list<base_descriptor<C, Bs>...>;
};
#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__) ); }
#else
#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<C, boost::describe::detail::list<__VA_ARGS__>>::type(); }
} // namespace detail
} // namespace describe

View File

@@ -62,6 +62,14 @@ int main() {}
#include <boost/mp11.hpp>
template<typename ...Bases>
struct ZT: Bases...
{
BOOST_DESCRIBE_CLASS(ZT, (Bases...), (), (), ());
};
using Z = ZT<X1, X2, X3>;
int main()
{
using namespace boost::describe;
@@ -151,6 +159,21 @@ int main()
BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_private | mod_virtual );
}
{
using L = describe_bases<Z, mod_any_access>;
BOOST_TEST_EQ( mp_size<L>::value, 3 );
BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );
BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, X2 );
BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public );
BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 2>::type, X3 );
BOOST_TEST_EQ( (mp_at_c<L, 2>::modifiers), mod_public );
}
return boost::report_errors();
}