Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.7KB

  1. //
  2. // associated_allocator.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_ASSOCIATED_ALLOCATOR_HPP
  11. #define ASIO_ASSOCIATED_ALLOCATOR_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 <memory>
  17. #include "asio/detail/type_traits.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. template <typename>
  22. struct associated_allocator_check
  23. {
  24. typedef void type;
  25. };
  26. template <typename T, typename E, typename = void>
  27. struct associated_allocator_impl
  28. {
  29. typedef E type;
  30. static type get(const T&, const E& e) ASIO_NOEXCEPT
  31. {
  32. return e;
  33. }
  34. };
  35. template <typename T, typename E>
  36. struct associated_allocator_impl<T, E,
  37. typename associated_allocator_check<typename T::allocator_type>::type>
  38. {
  39. typedef typename T::allocator_type type;
  40. static type get(const T& t, const E&) ASIO_NOEXCEPT
  41. {
  42. return t.get_allocator();
  43. }
  44. };
  45. } // namespace detail
  46. /// Traits type used to obtain the allocator associated with an object.
  47. /**
  48. * A program may specialise this traits type if the @c T template parameter in
  49. * the specialisation is a user-defined type. The template parameter @c
  50. * Allocator shall be a type meeting the Allocator requirements.
  51. *
  52. * Specialisations shall meet the following requirements, where @c t is a const
  53. * reference to an object of type @c T, and @c a is an object of type @c
  54. * Allocator.
  55. *
  56. * @li Provide a nested typedef @c type that identifies a type meeting the
  57. * Allocator requirements.
  58. *
  59. * @li Provide a noexcept static member function named @c get, callable as @c
  60. * get(t) and with return type @c type.
  61. *
  62. * @li Provide a noexcept static member function named @c get, callable as @c
  63. * get(t,a) and with return type @c type.
  64. */
  65. template <typename T, typename Allocator = std::allocator<void> >
  66. struct associated_allocator
  67. {
  68. /// If @c T has a nested type @c allocator_type, <tt>T::allocator_type</tt>.
  69. /// Otherwise @c Allocator.
  70. #if defined(GENERATING_DOCUMENTATION)
  71. typedef see_below type;
  72. #else // defined(GENERATING_DOCUMENTATION)
  73. typedef typename detail::associated_allocator_impl<T, Allocator>::type type;
  74. #endif // defined(GENERATING_DOCUMENTATION)
  75. /// If @c T has a nested type @c allocator_type, returns
  76. /// <tt>t.get_allocator()</tt>. Otherwise returns @c a.
  77. static type get(const T& t,
  78. const Allocator& a = Allocator()) ASIO_NOEXCEPT
  79. {
  80. return detail::associated_allocator_impl<T, Allocator>::get(t, a);
  81. }
  82. };
  83. /// Helper function to obtain an object's associated allocator.
  84. /**
  85. * @returns <tt>associated_allocator<T>::get(t)</tt>
  86. */
  87. template <typename T>
  88. inline typename associated_allocator<T>::type
  89. get_associated_allocator(const T& t) ASIO_NOEXCEPT
  90. {
  91. return associated_allocator<T>::get(t);
  92. }
  93. /// Helper function to obtain an object's associated allocator.
  94. /**
  95. * @returns <tt>associated_allocator<T, Allocator>::get(t, a)</tt>
  96. */
  97. template <typename T, typename Allocator>
  98. inline typename associated_allocator<T, Allocator>::type
  99. get_associated_allocator(const T& t, const Allocator& a) ASIO_NOEXCEPT
  100. {
  101. return associated_allocator<T, Allocator>::get(t, a);
  102. }
  103. #if defined(ASIO_HAS_ALIAS_TEMPLATES)
  104. template <typename T, typename Allocator = std::allocator<void> >
  105. using associated_allocator_t
  106. = typename associated_allocator<T, Allocator>::type;
  107. #endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
  108. } // namespace asio
  109. #include "asio/detail/pop_options.hpp"
  110. #endif // ASIO_ASSOCIATED_ALLOCATOR_HPP