| 1 | #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_POINTER_HPP_INCLUDED |
| 2 | #define BOOST_DESCRIBE_DESCRIPTOR_BY_POINTER_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/config.hpp> |
| 9 | |
| 10 | #if defined(__cpp_nontype_template_parameter_auto) && __cpp_nontype_template_parameter_auto >= 201606L |
| 11 | |
| 12 | #include <boost/mp11/algorithm.hpp> |
| 13 | #include <boost/mp11/bind.hpp> |
| 14 | #include <boost/mp11/integral.hpp> |
| 15 | |
| 16 | namespace boost |
| 17 | { |
| 18 | namespace describe |
| 19 | { |
| 20 | |
| 21 | namespace detail |
| 22 | { |
| 23 | |
| 24 | template<class Pm> constexpr bool cx_pmeq( Pm p1, Pm p2 ) |
| 25 | { |
| 26 | return p1 == p2; |
| 27 | } |
| 28 | |
| 29 | template<class Pm1, class Pm2> constexpr bool cx_pmeq( Pm1, Pm2 ) |
| 30 | { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | template<auto Pm> struct match_by_pointer |
| 35 | { |
| 36 | template<class D> using fn = mp11::mp_bool< cx_pmeq( D::pointer, Pm ) >; |
| 37 | }; |
| 38 | |
| 39 | } // namespace detail |
| 40 | |
| 41 | template<class L, auto Pm> using descriptor_by_pointer = mp11::mp_at<L, mp11::mp_find_if_q<L, detail::match_by_pointer<Pm>>>; |
| 42 | |
| 43 | } // namespace describe |
| 44 | } // namespace boost |
| 45 | |
| 46 | #endif // __cpp_nontype_template_parameter_auto |
| 47 | |
| 48 | #endif // #ifndef BOOST_DESCRIBE_DESCRIPTOR_BY_POINTER_HPP_INCLUDED |
| 49 | |