Skip to content

Commit 0bf2edd

Browse files
committed
更新ASIO
1 parent 402ee58 commit 0bf2edd

File tree

505 files changed

+91395
-68455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

505 files changed

+91395
-68455
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//
2+
// associated_allocator.hpp
3+
// ~~~~~~~~~~~~~~~~~~~~~~~~
4+
//
5+
// Copyright (c) 2003-2018 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>
28+
struct associated_allocator_check
29+
{
30+
typedef void type;
31+
};
32+
33+
template <typename T, typename E, typename = void>
34+
struct associated_allocator_impl
35+
{
36+
typedef E type;
37+
38+
static type get(const T&, const E& e) ASIO_NOEXCEPT
39+
{
40+
return e;
41+
}
42+
};
43+
44+
template <typename T, typename E>
45+
struct associated_allocator_impl<T, E,
46+
typename associated_allocator_check<typename T::allocator_type>::type>
47+
{
48+
typedef typename T::allocator_type type;
49+
50+
static type get(const T& t, const E&) ASIO_NOEXCEPT
51+
{
52+
return t.get_allocator();
53+
}
54+
};
55+
56+
} // namespace detail
57+
58+
/// Traits type used to obtain the allocator associated with an object.
59+
/**
60+
* A program may specialise this traits type if the @c T template parameter in
61+
* the specialisation is a user-defined type. The template parameter @c
62+
* Allocator shall be a type meeting the Allocator requirements.
63+
*
64+
* Specialisations shall meet the following requirements, where @c t is a const
65+
* reference to an object of type @c T, and @c a is an object of type @c
66+
* Allocator.
67+
*
68+
* @li Provide a nested typedef @c type that identifies a type meeting the
69+
* Allocator requirements.
70+
*
71+
* @li Provide a noexcept static member function named @c get, callable as @c
72+
* get(t) and with return type @c type.
73+
*
74+
* @li Provide a noexcept static member function named @c get, callable as @c
75+
* get(t,a) and with return type @c type.
76+
*/
77+
template <typename T, typename Allocator = std::allocator<void> >
78+
struct associated_allocator
79+
{
80+
/// If @c T has a nested type @c allocator_type, <tt>T::allocator_type</tt>.
81+
/// Otherwise @c Allocator.
82+
#if defined(GENERATING_DOCUMENTATION)
83+
typedef see_below type;
84+
#else // defined(GENERATING_DOCUMENTATION)
85+
typedef typename detail::associated_allocator_impl<T, Allocator>::type type;
86+
#endif // defined(GENERATING_DOCUMENTATION)
87+
88+
/// If @c T has a nested type @c allocator_type, returns
89+
/// <tt>t.get_allocator()</tt>. Otherwise returns @c a.
90+
static type get(const T& t,
91+
const Allocator& a = Allocator()) ASIO_NOEXCEPT
92+
{
93+
return detail::associated_allocator_impl<T, Allocator>::get(t, a);
94+
}
95+
};
96+
97+
/// Helper function to obtain an object's associated allocator.
98+
/**
99+
* @returns <tt>associated_allocator<T>::get(t)</tt>
100+
*/
101+
template <typename T>
102+
inline typename associated_allocator<T>::type
103+
get_associated_allocator(const T& t) ASIO_NOEXCEPT
104+
{
105+
return associated_allocator<T>::get(t);
106+
}
107+
108+
/// Helper function to obtain an object's associated allocator.
109+
/**
110+
* @returns <tt>associated_allocator<T, Allocator>::get(t, a)</tt>
111+
*/
112+
template <typename T, typename Allocator>
113+
inline typename associated_allocator<T, Allocator>::type
114+
get_associated_allocator(const T& t, const Allocator& a) ASIO_NOEXCEPT
115+
{
116+
return associated_allocator<T, Allocator>::get(t, a);
117+
}
118+
119+
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
120+
121+
template <typename T, typename Allocator = std::allocator<void> >
122+
using associated_allocator_t
123+
= typename associated_allocator<T, Allocator>::type;
124+
125+
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
126+
127+
} // namespace asio
128+
129+
#include "asio/detail/pop_options.hpp"
130+
131+
#endif // ASIO_ASSOCIATED_ALLOCATOR_HPP
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
//
2+
// associated_executor.hpp
3+
// ~~~~~~~~~~~~~~~~~~~~~~~
4+
//
5+
// Copyright (c) 2003-2018 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_EXECUTOR_HPP
12+
#define ASIO_ASSOCIATED_EXECUTOR_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 "asio/detail/type_traits.hpp"
20+
#include "asio/is_executor.hpp"
21+
#include "asio/system_executor.hpp"
22+
23+
#include "asio/detail/push_options.hpp"
24+
25+
namespace asio {
26+
namespace detail {
27+
28+
template <typename>
29+
struct associated_executor_check
30+
{
31+
typedef void type;
32+
};
33+
34+
template <typename T, typename E, typename = void>
35+
struct associated_executor_impl
36+
{
37+
typedef E type;
38+
39+
static type get(const T&, const E& e) ASIO_NOEXCEPT
40+
{
41+
return e;
42+
}
43+
};
44+
45+
template <typename T, typename E>
46+
struct associated_executor_impl<T, E,
47+
typename associated_executor_check<typename T::executor_type>::type>
48+
{
49+
typedef typename T::executor_type type;
50+
51+
static type get(const T& t, const E&) ASIO_NOEXCEPT
52+
{
53+
return t.get_executor();
54+
}
55+
};
56+
57+
} // namespace detail
58+
59+
/// Traits type used to obtain the executor associated with an object.
60+
/**
61+
* A program may specialise this traits type if the @c T template parameter in
62+
* the specialisation is a user-defined type. The template parameter @c
63+
* Executor shall be a type meeting the Executor requirements.
64+
*
65+
* Specialisations shall meet the following requirements, where @c t is a const
66+
* reference to an object of type @c T, and @c e is an object of type @c
67+
* Executor.
68+
*
69+
* @li Provide a nested typedef @c type that identifies a type meeting the
70+
* Executor requirements.
71+
*
72+
* @li Provide a noexcept static member function named @c get, callable as @c
73+
* get(t) and with return type @c type.
74+
*
75+
* @li Provide a noexcept static member function named @c get, callable as @c
76+
* get(t,e) and with return type @c type.
77+
*/
78+
template <typename T, typename Executor = system_executor>
79+
struct associated_executor
80+
{
81+
/// If @c T has a nested type @c executor_type, <tt>T::executor_type</tt>.
82+
/// Otherwise @c Executor.
83+
#if defined(GENERATING_DOCUMENTATION)
84+
typedef see_below type;
85+
#else // defined(GENERATING_DOCUMENTATION)
86+
typedef typename detail::associated_executor_impl<T, Executor>::type type;
87+
#endif // defined(GENERATING_DOCUMENTATION)
88+
89+
/// If @c T has a nested type @c executor_type, returns
90+
/// <tt>t.get_executor()</tt>. Otherwise returns @c ex.
91+
static type get(const T& t,
92+
const Executor& ex = Executor()) ASIO_NOEXCEPT
93+
{
94+
return detail::associated_executor_impl<T, Executor>::get(t, ex);
95+
}
96+
};
97+
98+
/// Helper function to obtain an object's associated executor.
99+
/**
100+
* @returns <tt>associated_executor<T>::get(t)</tt>
101+
*/
102+
template <typename T>
103+
inline typename associated_executor<T>::type
104+
get_associated_executor(const T& t) ASIO_NOEXCEPT
105+
{
106+
return associated_executor<T>::get(t);
107+
}
108+
109+
/// Helper function to obtain an object's associated executor.
110+
/**
111+
* @returns <tt>associated_executor<T, Executor>::get(t, ex)</tt>
112+
*/
113+
template <typename T, typename Executor>
114+
inline typename associated_executor<T, Executor>::type
115+
get_associated_executor(const T& t, const Executor& ex,
116+
typename enable_if<is_executor<
117+
Executor>::value>::type* = 0) ASIO_NOEXCEPT
118+
{
119+
return associated_executor<T, Executor>::get(t, ex);
120+
}
121+
122+
/// Helper function to obtain an object's associated executor.
123+
/**
124+
* @returns <tt>associated_executor<T, typename
125+
* ExecutionContext::executor_type>::get(t, ctx.get_executor())</tt>
126+
*/
127+
template <typename T, typename ExecutionContext>
128+
inline typename associated_executor<T,
129+
typename ExecutionContext::executor_type>::type
130+
get_associated_executor(const T& t, ExecutionContext& ctx,
131+
typename enable_if<is_convertible<ExecutionContext&,
132+
execution_context&>::value>::type* = 0) ASIO_NOEXCEPT
133+
{
134+
return associated_executor<T,
135+
typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
136+
}
137+
138+
#if defined(ASIO_HAS_ALIAS_TEMPLATES)
139+
140+
template <typename T, typename Executor = system_executor>
141+
using associated_executor_t = typename associated_executor<T, Executor>::type;
142+
143+
#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
144+
145+
} // namespace asio
146+
147+
#include "asio/detail/pop_options.hpp"
148+
149+
#endif // ASIO_ASSOCIATED_EXECUTOR_HPP

0 commit comments

Comments
 (0)