start_free.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // traits/start_free.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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_START_FREE_HPP
  11. #define ASIO_TRAITS_START_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_DECLTYPE) \
  18. && defined(ASIO_HAS_NOEXCEPT) \
  19. && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. # define ASIO_HAS_DEDUCED_START_FREE_TRAIT 1
  21. #endif // defined(ASIO_HAS_DECLTYPE)
  22. // && defined(ASIO_HAS_NOEXCEPT)
  23. // && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  24. #include "asio/detail/push_options.hpp"
  25. namespace asio {
  26. namespace traits {
  27. template <typename T, typename = void>
  28. struct start_free_default;
  29. template <typename T, typename = void>
  30. struct start_free;
  31. } // namespace traits
  32. namespace detail {
  33. struct no_start_free
  34. {
  35. ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  36. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  37. };
  38. #if defined(ASIO_HAS_DEDUCED_START_FREE_TRAIT)
  39. template <typename T, typename = void>
  40. struct start_free_trait : no_start_free
  41. {
  42. };
  43. template <typename T>
  44. struct start_free_trait<T,
  45. typename void_type<
  46. decltype(start(declval<T>()))
  47. >::type>
  48. {
  49. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  50. using result_type = decltype(start(declval<T>()));
  51. ASIO_STATIC_CONSTEXPR(bool,
  52. is_noexcept = noexcept(start(declval<T>())));
  53. };
  54. #else // defined(ASIO_HAS_DEDUCED_START_FREE_TRAIT)
  55. template <typename T, typename = void>
  56. struct start_free_trait :
  57. conditional<
  58. is_same<T, typename remove_reference<T>::type>::value,
  59. typename conditional<
  60. is_same<T, typename add_const<T>::type>::value,
  61. no_start_free,
  62. traits::start_free<typename add_const<T>::type>
  63. >::type,
  64. traits::start_free<typename remove_reference<T>::type>
  65. >::type
  66. {
  67. };
  68. #endif // defined(ASIO_HAS_DEDUCED_START_FREE_TRAIT)
  69. } // namespace detail
  70. namespace traits {
  71. template <typename T, typename>
  72. struct start_free_default :
  73. detail::start_free_trait<T>
  74. {
  75. };
  76. template <typename T, typename>
  77. struct start_free :
  78. start_free_default<T>
  79. {
  80. };
  81. } // namespace traits
  82. } // namespace asio
  83. #include "asio/detail/pop_options.hpp"
  84. #endif // ASIO_TRAITS_START_FREE_HPP