prefer_member.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // traits/prefer_member.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP
  11. #define BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  18. # define BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT 1
  19. #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace traits {
  24. template <typename T, typename Property, typename = void>
  25. struct prefer_member_default;
  26. template <typename T, typename Property, typename = void>
  27. struct prefer_member;
  28. } // namespace traits
  29. namespace detail {
  30. struct no_prefer_member
  31. {
  32. static constexpr bool is_valid = false;
  33. static constexpr bool is_noexcept = false;
  34. };
  35. #if defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
  36. template <typename T, typename Property, typename = void>
  37. struct prefer_member_trait : no_prefer_member
  38. {
  39. };
  40. template <typename T, typename Property>
  41. struct prefer_member_trait<T, Property,
  42. void_t<
  43. decltype(declval<T>().prefer(declval<Property>()))
  44. >>
  45. {
  46. static constexpr bool is_valid = true;
  47. using result_type = decltype(
  48. declval<T>().prefer(declval<Property>()));
  49. static constexpr bool is_noexcept =
  50. noexcept(declval<T>().prefer(declval<Property>()));
  51. };
  52. #else // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
  53. template <typename T, typename Property, typename = void>
  54. struct prefer_member_trait :
  55. conditional_t<
  56. is_same<T, decay_t<T>>::value
  57. && is_same<Property, decay_t<Property>>::value,
  58. no_prefer_member,
  59. traits::prefer_member<
  60. decay_t<T>,
  61. decay_t<Property>>
  62. >
  63. {
  64. };
  65. #endif // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
  66. } // namespace detail
  67. namespace traits {
  68. template <typename T, typename Property, typename>
  69. struct prefer_member_default :
  70. detail::prefer_member_trait<T, Property>
  71. {
  72. };
  73. template <typename T, typename Property, typename>
  74. struct prefer_member :
  75. prefer_member_default<T, Property>
  76. {
  77. };
  78. } // namespace traits
  79. } // namespace asio
  80. } // namespace boost
  81. #include <boost/asio/detail/pop_options.hpp>
  82. #endif // BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP