• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // detail/is_executor.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 
11 #ifndef BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP
12 #define BOOST_ASIO_DETAIL_IS_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 <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/type_traits.hpp>
20 
21 #include <boost/asio/detail/push_options.hpp>
22 
23 namespace boost {
24 namespace asio {
25 namespace detail {
26 
27 struct executor_memfns_base
28 {
29   void context();
30   void on_work_started();
31   void on_work_finished();
32   void dispatch();
33   void post();
34   void defer();
35 };
36 
37 template <typename T>
38 struct executor_memfns_derived
39   : T, executor_memfns_base
40 {
41 };
42 
43 template <typename T, T>
44 struct executor_memfns_check
45 {
46 };
47 
48 template <typename>
49 char (&context_memfn_helper(...))[2];
50 
51 template <typename T>
52 char context_memfn_helper(
53     executor_memfns_check<
54       void (executor_memfns_base::*)(),
55       &executor_memfns_derived<T>::context>*);
56 
57 template <typename>
58 char (&on_work_started_memfn_helper(...))[2];
59 
60 template <typename T>
61 char on_work_started_memfn_helper(
62     executor_memfns_check<
63       void (executor_memfns_base::*)(),
64       &executor_memfns_derived<T>::on_work_started>*);
65 
66 template <typename>
67 char (&on_work_finished_memfn_helper(...))[2];
68 
69 template <typename T>
70 char on_work_finished_memfn_helper(
71     executor_memfns_check<
72       void (executor_memfns_base::*)(),
73       &executor_memfns_derived<T>::on_work_finished>*);
74 
75 template <typename>
76 char (&dispatch_memfn_helper(...))[2];
77 
78 template <typename T>
79 char dispatch_memfn_helper(
80     executor_memfns_check<
81       void (executor_memfns_base::*)(),
82       &executor_memfns_derived<T>::dispatch>*);
83 
84 template <typename>
85 char (&post_memfn_helper(...))[2];
86 
87 template <typename T>
88 char post_memfn_helper(
89     executor_memfns_check<
90       void (executor_memfns_base::*)(),
91       &executor_memfns_derived<T>::post>*);
92 
93 template <typename>
94 char (&defer_memfn_helper(...))[2];
95 
96 template <typename T>
97 char defer_memfn_helper(
98     executor_memfns_check<
99       void (executor_memfns_base::*)(),
100       &executor_memfns_derived<T>::defer>*);
101 
102 template <typename T>
103 struct is_executor_class
104   : integral_constant<bool,
105       sizeof(context_memfn_helper<T>(0)) != 1 &&
106       sizeof(on_work_started_memfn_helper<T>(0)) != 1 &&
107       sizeof(on_work_finished_memfn_helper<T>(0)) != 1 &&
108       sizeof(dispatch_memfn_helper<T>(0)) != 1 &&
109       sizeof(post_memfn_helper<T>(0)) != 1 &&
110       sizeof(defer_memfn_helper<T>(0)) != 1>
111 {
112 };
113 
114 template <typename T>
115 struct is_executor
116   : conditional<is_class<T>::value,
117       is_executor_class<T>,
118       false_type>::type
119 {
120 };
121 
122 } // namespace detail
123 } // namespace asio
124 } // namespace boost
125 
126 #include <boost/asio/detail/pop_options.hpp>
127 
128 #endif // BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP
129