bases.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // bases_descriptor
  27. template<typename ...>
  28. struct bases_descriptor_impl;
  29. template<class C, class ...Bs>
  30. struct bases_descriptor_impl<C, list<Bs...>>
  31. {
  32. using type = list<base_descriptor<C, Bs>...>;
  33. };
  34. #define BOOST_DESCRIBE_BASES(C, ...) inline auto boost_base_descriptor_fn( C** ) \
  35. { return typename boost::describe::detail::bases_descriptor_impl<C, boost::describe::detail::list<__VA_ARGS__>>::type(); }
  36. } // namespace detail
  37. } // namespace describe
  38. } // namespace boost
  39. #endif // #ifndef BOOST_DESCRIBE_DETAIL_BASES_HPP_INCLUDED