start_free.hpp 2.6 KB

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