descriptor_by_pointer.hpp 1.1 KB

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