descriptor_by_name.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED
  2. #define BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED
  3. // Copyright 2021 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/cx_streq.hpp>
  7. #include <boost/describe/detail/config.hpp>
  8. #if defined(BOOST_DESCRIBE_CXX14)
  9. #include <boost/mp11/algorithm.hpp>
  10. #include <boost/mp11/bind.hpp>
  11. #include <boost/mp11/integral.hpp>
  12. namespace boost
  13. {
  14. namespace describe
  15. {
  16. namespace detail
  17. {
  18. template<class D, class N> using match_by_name = mp11::mp_bool<cx_streq(N::name(), D::name)>;
  19. #define BOOST_DESCRIBE_MAKE_NAME_IMPL2(s, k) struct _boost_name_##s##_##k { static constexpr char const * name() { return #s; } }
  20. #define BOOST_DESCRIBE_MAKE_NAME_IMPL(s, k) BOOST_DESCRIBE_MAKE_NAME_IMPL2(s, k)
  21. } // namespace detail
  22. #define BOOST_DESCRIBE_MAKE_NAME(s) BOOST_DESCRIBE_MAKE_NAME_IMPL(s, __LINE__)
  23. template<class L, class N> using descriptor_by_name = mp11::mp_at<L, mp11::mp_find_if_q<L, mp11::mp_bind_back<detail::match_by_name, N>>>;
  24. } // namespace describe
  25. } // namespace boost
  26. #endif // defined(BOOST_DESCRIBE_CXX14)
  27. #endif // #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED