memory.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // detail/memory.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_DETAIL_MEMORY_HPP
  11. #define BOOST_ASIO_DETAIL_MEMORY_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 <memory>
  17. #if !defined(BOOST_ASIO_HAS_STD_SHARED_PTR)
  18. # include <boost/make_shared.hpp>
  19. # include <boost/shared_ptr.hpp>
  20. # include <boost/weak_ptr.hpp>
  21. #endif // !defined(BOOST_ASIO_HAS_STD_SHARED_PTR)
  22. #if !defined(BOOST_ASIO_HAS_STD_ADDRESSOF)
  23. # include <boost/utility/addressof.hpp>
  24. #endif // !defined(BOOST_ASIO_HAS_STD_ADDRESSOF)
  25. namespace boost {
  26. namespace asio {
  27. namespace detail {
  28. #if defined(BOOST_ASIO_HAS_STD_SHARED_PTR)
  29. using std::make_shared;
  30. using std::shared_ptr;
  31. using std::weak_ptr;
  32. #else // defined(BOOST_ASIO_HAS_STD_SHARED_PTR)
  33. using boost::make_shared;
  34. using boost::shared_ptr;
  35. using boost::weak_ptr;
  36. #endif // defined(BOOST_ASIO_HAS_STD_SHARED_PTR)
  37. #if defined(BOOST_ASIO_HAS_STD_ADDRESSOF)
  38. using std::addressof;
  39. #else // defined(BOOST_ASIO_HAS_STD_ADDRESSOF)
  40. using boost::addressof;
  41. #endif // defined(BOOST_ASIO_HAS_STD_ADDRESSOF)
  42. } // namespace detail
  43. #if defined(BOOST_ASIO_HAS_CXX11_ALLOCATORS)
  44. using std::allocator_arg_t;
  45. # define BOOST_ASIO_USES_ALLOCATOR(t) \
  46. namespace std { \
  47. template <typename Allocator> \
  48. struct uses_allocator<t, Allocator> : true_type {}; \
  49. } \
  50. /**/
  51. # define BOOST_ASIO_REBIND_ALLOC(alloc, t) \
  52. typename std::allocator_traits<alloc>::template rebind_alloc<t>
  53. /**/
  54. #else // defined(BOOST_ASIO_HAS_CXX11_ALLOCATORS)
  55. struct allocator_arg_t {};
  56. # define BOOST_ASIO_USES_ALLOCATOR(t)
  57. # define BOOST_ASIO_REBIND_ALLOC(alloc, t) \
  58. typename alloc::template rebind<t>::other
  59. /**/
  60. #endif // defined(BOOST_ASIO_HAS_CXX11_ALLOCATORS)
  61. } // namespace asio
  62. } // namespace boost
  63. #endif // BOOST_ASIO_DETAIL_MEMORY_HPP