Skip to content

Commit

Permalink
Merge pull request #47 from qchateau/develop
Browse files Browse the repository at this point in the history
Support parameter packs for bases in BOOST_DESCRIBE_CLASS
  • Loading branch information
pdimov authored Oct 13, 2024
2 parents 18e7c01 + 2e63564 commit ff76bbb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
24 changes: 9 additions & 15 deletions include/boost/describe/detail/bases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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... )
{
return list<T...>();
}

#define BOOST_DESCRIBE_BASE_IMPL(C, B) , boost::describe::detail::base_descriptor<C, B>()

#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<typename ...>
struct bases_descriptor_impl;

#else
template<class C, class ...Bs>
struct bases_descriptor_impl<C, list<Bs...>>
{
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__) ); }

#endif
{ return typename boost::describe::detail::bases_descriptor_impl<C, boost::describe::detail::list<__VA_ARGS__>>::type(); }

} // namespace detail
} // namespace describe
Expand Down
23 changes: 23 additions & 0 deletions test/bases_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit ff76bbb

Please sign in to comment.