bases.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef BOOST_DESCRIBE_DETAIL_BASES_HPP_INCLUDED
  2. #define BOOST_DESCRIBE_DETAIL_BASES_HPP_INCLUDED
  3. // Copyright 2020 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/describe/detail/compute_base_modifiers.hpp>
  7. #include <boost/describe/detail/pp_for_each.hpp>
  8. #include <boost/describe/detail/list.hpp>
  9. #include <type_traits>
  10. namespace boost
  11. {
  12. namespace describe
  13. {
  14. namespace detail
  15. {
  16. // base_descriptor
  17. template<class C, class B> struct base_descriptor
  18. {
  19. static_assert( std::is_base_of<B, C>::value, "A type listed as a base is not one" );
  20. using type = B;
  21. static constexpr unsigned modifiers = compute_base_modifiers<C, B>();
  22. };
  23. template<class C, class B> constexpr unsigned base_descriptor<C, B>::modifiers;
  24. template<class... T> auto base_descriptor_fn_impl( int, T... )
  25. {
  26. return list<T...>();
  27. }
  28. #define BOOST_DESCRIBE_BASE_IMPL(C, B) , boost::describe::detail::base_descriptor<C, B>()
  29. #if defined(_MSC_VER) && !defined(__clang__)
  30. #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \
  31. { return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, __VA_ARGS__) ); }
  32. #else
  33. #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \
  34. { return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, ##__VA_ARGS__) ); }
  35. #endif
  36. } // namespace detail
  37. } // namespace describe
  38. } // namespace boost
  39. #endif // #ifndef BOOST_DESCRIBE_DETAIL_BASES_HPP_INCLUDED