| 1 | #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED |
| 2 | #define BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2021 Peter Dimov |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // https://www.boost.org/LICENSE_1_0.txt |
| 7 | |
| 8 | #include <boost/describe/detail/cx_streq.hpp> |
| 9 | #include <boost/describe/detail/config.hpp> |
| 10 | |
| 11 | #if defined(BOOST_DESCRIBE_CXX14) |
| 12 | |
| 13 | #include <boost/mp11/algorithm.hpp> |
| 14 | #include <boost/mp11/bind.hpp> |
| 15 | #include <boost/mp11/integral.hpp> |
| 16 | |
| 17 | namespace boost |
| 18 | { |
| 19 | namespace describe |
| 20 | { |
| 21 | |
| 22 | namespace detail |
| 23 | { |
| 24 | |
| 25 | template<class D, class N> using match_by_name = mp11::mp_bool<cx_streq(N::name(), D::name)>; |
| 26 | |
| 27 | #define BOOST_DESCRIBE_MAKE_NAME_IMPL2(s, k) struct _boost_name_##s##_##k { static constexpr char const * name() { return #s; } } |
| 28 | #define BOOST_DESCRIBE_MAKE_NAME_IMPL(s, k) BOOST_DESCRIBE_MAKE_NAME_IMPL2(s, k) |
| 29 | |
| 30 | } // namespace detail |
| 31 | |
| 32 | #define BOOST_DESCRIBE_MAKE_NAME(s) BOOST_DESCRIBE_MAKE_NAME_IMPL(s, __LINE__) |
| 33 | |
| 34 | 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>>>; |
| 35 | |
| 36 | } // namespace describe |
| 37 | } // namespace boost |
| 38 | |
| 39 | #endif // defined(BOOST_DESCRIBE_CXX14) |
| 40 | |
| 41 | #endif // #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_NAME_HPP_INCLUDED |
| 42 | |