bases.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef __cpp_inline_variables
  24. template<class C, class B> constexpr unsigned base_descriptor<C, B>::modifiers;
  25. #endif
  26. template<class... T> auto base_descriptor_fn_impl( int, T... )
  27. {
  28. return list<T...>();
  29. }
  30. #define BOOST_DESCRIBE_BASE_IMPL(C, B) , boost::describe::detail::base_descriptor<C, B>()
  31. #if defined(_MSC_VER) && !defined(__clang__)
  32. #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \
  33. { return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, __VA_ARGS__) ); }
  34. #else
  35. #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \
  36. { return boost::describe::detail::base_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_BASE_IMPL, C, ##__VA_ARGS__) ); }
  37. #endif
  38. } // namespace detail
  39. } // namespace describe
  40. } // namespace boost
  41. #endif // #ifndef BOOST_DESCRIBE_DETAIL_BASES_HPP_INCLUDED