prefer_free.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // traits/prefer_free.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_TRAITS_PREFER_FREE_HPP
  11. #define ASIO_TRAITS_PREFER_FREE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/type_traits.hpp"
  17. #if defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  18. # define ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT 1
  19. #endif // defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace traits {
  23. template <typename T, typename Property, typename = void>
  24. struct prefer_free_default;
  25. template <typename T, typename Property, typename = void>
  26. struct prefer_free;
  27. } // namespace traits
  28. namespace detail {
  29. struct no_prefer_free
  30. {
  31. static constexpr bool is_valid = false;
  32. static constexpr bool is_noexcept = false;
  33. };
  34. #if defined(ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
  35. template <typename T, typename Property, typename = void>
  36. struct prefer_free_trait : no_prefer_free
  37. {
  38. };
  39. template <typename T, typename Property>
  40. struct prefer_free_trait<T, Property,
  41. void_t<
  42. decltype(prefer(declval<T>(), declval<Property>()))
  43. >>
  44. {
  45. static constexpr bool is_valid = true;
  46. using result_type = decltype(
  47. prefer(declval<T>(), declval<Property>()));
  48. static constexpr bool is_noexcept =
  49. noexcept(prefer(declval<T>(), declval<Property>()));
  50. };
  51. #else // defined(ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
  52. template <typename T, typename Property, typename = void>
  53. struct prefer_free_trait :
  54. conditional_t<
  55. is_same<T, decay_t<T>>::value
  56. && is_same<Property, decay_t<Property>>::value,
  57. no_prefer_free,
  58. traits::prefer_free<
  59. decay_t<T>,
  60. decay_t<Property>>
  61. >
  62. {
  63. };
  64. #endif // defined(ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
  65. } // namespace detail
  66. namespace traits {
  67. template <typename T, typename Property, typename>
  68. struct prefer_free_default :
  69. detail::prefer_free_trait<T, Property>
  70. {
  71. };
  72. template <typename T, typename Property, typename>
  73. struct prefer_free :
  74. prefer_free_default<T, Property>
  75. {
  76. };
  77. } // namespace traits
  78. } // namespace asio
  79. #include "asio/detail/pop_options.hpp"
  80. #endif // ASIO_TRAITS_PREFER_FREE_HPP