Clementine
associated_allocator.hpp
1 //
2 // associated_allocator.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 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 
11 #ifndef ASIO_ASSOCIATED_ALLOCATOR_HPP
12 #define ASIO_ASSOCIATED_ALLOCATOR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include <memory>
20 #include "asio/detail/type_traits.hpp"
21 
22 #include "asio/detail/push_options.hpp"
23 
24 namespace asio {
25 namespace detail {
26 
27 template <typename T, typename E, typename = void>
29 {
30  typedef E type;
31 
32  static type get(const T&, const E& e) ASIO_NOEXCEPT
33  {
34  return e;
35  }
36 };
37 
38 template <typename T, typename E>
40  typename void_type<typename T::allocator_type>::type>
41 {
42  typedef typename T::allocator_type type;
43 
44  static type get(const T& t, const E&) ASIO_NOEXCEPT
45  {
46  return t.get_allocator();
47  }
48 };
49 
50 } // namespace detail
51 
53 
71 template <typename T, typename Allocator = std::allocator<void> >
73 {
76 #if defined(GENERATING_DOCUMENTATION)
77  typedef see_below type;
78 #else // defined(GENERATING_DOCUMENTATION)
79  typedef typename detail::associated_allocator_impl<T, Allocator>::type type;
80 #endif // defined(GENERATING_DOCUMENTATION)
81 
84  static type get(const T& t,
85  const Allocator& a = Allocator()) ASIO_NOEXCEPT
86  {
88  }
89 };
90 
92 
95 template <typename T>
96 inline typename associated_allocator<T>::type
97 get_associated_allocator(const T& t) ASIO_NOEXCEPT
98 {
100 }
101 
103 
106 template <typename T, typename Allocator>
108 get_associated_allocator(const T& t, const Allocator& a) ASIO_NOEXCEPT
109 {
111 }
112 
113 #if defined(ASIO_HAS_ALIAS_TEMPLATES)
114 
115 template <typename T, typename Allocator = std::allocator<void> >
116 using associated_allocator_t
118 
119 #endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
120 
121 } // namespace asio
122 
123 #include "asio/detail/pop_options.hpp"
124 
125 #endif // ASIO_ASSOCIATED_ALLOCATOR_HPP
Definition: type_traits.hpp:135
static type get(const T &t, const Allocator &a=Allocator()) ASIO_NOEXCEPT
If T has a nested type allocator_type, returns t.get_allocator().
Definition: associated_allocator.hpp:84
Definition: chrono.h:284
Traits type used to obtain the allocator associated with an object.
Definition: associated_allocator.hpp:72
Definition: associated_allocator.hpp:28
detail::associated_allocator_impl< T, Allocator >::type type
If T has a nested type allocator_type, T::allocator_type.
Definition: associated_allocator.hpp:79
Definition: any_io_executor.hpp:28