5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 // Disable autolinking for unit tests.
12 #if !defined(BOOST_ALL_NO_LIB)
13 #define BOOST_ALL_NO_LIB 1
14 #endif // !defined(BOOST_ALL_NO_LIB)
16 // Test that header file is self-contained.
17 #include <boost/asio/execution/bulk_execute.hpp>
19 #include <boost/asio/execution.hpp>
20 #include "../unit_test.hpp"
22 namespace exec
= boost::asio::execution
;
26 struct operation_state
28 void start() BOOST_ASIO_NOEXCEPT
37 #if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
40 struct start_member
<operation_state
>
42 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
43 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= true);
44 typedef void result_type
;
47 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
53 struct sender
: exec::sender_base
60 operation_state
connect(BOOST_ASIO_MOVE_ARG(R
) r
) const
63 return operation_state();
71 #if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
74 struct connect_member
<const sender
, R
>
76 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
77 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= false);
78 typedef operation_state result_type
;
81 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
87 struct no_bulk_execute
91 struct const_member_bulk_execute
93 const_member_bulk_execute()
98 sender
bulk_execute(BOOST_ASIO_MOVE_ARG(F
), std::size_t) const
109 #if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
111 template <typename F
, typename N
>
112 struct bulk_execute_member
<const const_member_bulk_execute
, F
, N
>
114 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
115 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= false);
116 typedef sender result_type
;
119 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
121 } // namespace traits
125 struct free_bulk_execute
131 template <typename F
>
132 friend sender
bulk_execute(const free_bulk_execute
&,
133 BOOST_ASIO_MOVE_ARG(F
), std::size_t)
144 #if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
146 template <typename F
, typename N
>
147 struct bulk_execute_free
<const free_bulk_execute
, F
, N
>
149 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
150 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= false);
151 typedef sender result_type
;
154 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
156 } // namespace traits
166 executor(const executor
&) BOOST_ASIO_NOEXCEPT
170 #if defined(BOOST_ASIO_HAS_MOVE)
171 executor(executor
&&) BOOST_ASIO_NOEXCEPT
174 #endif // defined(BOOST_ASIO_HAS_MOVE)
176 template <typename F
>
177 void execute(BOOST_ASIO_MOVE_ARG(F
) f
) const BOOST_ASIO_NOEXCEPT
179 typename
boost::asio::decay
<F
>::type
tmp(BOOST_ASIO_MOVE_CAST(F
)(f
));
183 bool operator==(const executor
&) const BOOST_ASIO_NOEXCEPT
188 bool operator!=(const executor
&) const BOOST_ASIO_NOEXCEPT
198 #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
200 template <typename F
>
201 struct execute_member
<executor
, F
>
203 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
204 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= true);
205 typedef void result_type
;
208 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
209 #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
212 struct equality_comparable
<executor
>
214 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid
= true);
215 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept
= true);
218 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
220 } // namespace traits
224 void test_can_bulk_execute()
226 BOOST_ASIO_CONSTEXPR
bool b1
= exec::can_bulk_execute
<
227 no_bulk_execute
&, exec::invocable_archetype
, std::size_t>::value
;
228 BOOST_ASIO_CHECK(b1
== false);
230 BOOST_ASIO_CONSTEXPR
bool b2
= exec::can_bulk_execute
<
231 const no_bulk_execute
&, exec::invocable_archetype
, std::size_t>::value
;
232 BOOST_ASIO_CHECK(b2
== false);
234 BOOST_ASIO_CONSTEXPR
bool b3
= exec::can_bulk_execute
<
235 const_member_bulk_execute
&, exec::invocable_archetype
, std::size_t>::value
;
236 BOOST_ASIO_CHECK(b3
== true);
238 BOOST_ASIO_CONSTEXPR
bool b4
= exec::can_bulk_execute
<
239 const const_member_bulk_execute
&,
240 exec::invocable_archetype
, std::size_t>::value
;
241 BOOST_ASIO_CHECK(b4
== true);
243 BOOST_ASIO_CONSTEXPR
bool b5
= exec::can_bulk_execute
<
244 free_bulk_execute
&, exec::invocable_archetype
, std::size_t>::value
;
245 BOOST_ASIO_CHECK(b5
== true);
247 BOOST_ASIO_CONSTEXPR
bool b6
= exec::can_bulk_execute
<
248 const free_bulk_execute
&, exec::invocable_archetype
, std::size_t>::value
;
249 BOOST_ASIO_CHECK(b6
== true);
251 BOOST_ASIO_CONSTEXPR
bool b7
= exec::can_bulk_execute
<
252 executor
&, exec::invocable_archetype
, std::size_t>::value
;
253 BOOST_ASIO_CHECK(b7
== true);
255 BOOST_ASIO_CONSTEXPR
bool b8
= exec::can_bulk_execute
<
256 const executor
&, exec::invocable_archetype
, std::size_t>::value
;
257 BOOST_ASIO_CHECK(b8
== true);
260 void handler(std::size_t)
264 void counting_handler(std::size_t)
269 void completion_handler()
274 void test_bulk_execute()
277 const_member_bulk_execute ex1
;
278 exec::bulk_execute(ex1
, handler
, 2);
279 BOOST_ASIO_CHECK(call_count
== 1);
282 const const_member_bulk_execute ex2
;
283 exec::bulk_execute(ex2
, handler
, 2);
284 BOOST_ASIO_CHECK(call_count
== 1);
287 exec::bulk_execute(const_member_bulk_execute(), handler
, 2);
288 BOOST_ASIO_CHECK(call_count
== 1);
291 free_bulk_execute ex3
;
292 exec::bulk_execute(ex3
, handler
, 2);
293 BOOST_ASIO_CHECK(call_count
== 1);
296 const free_bulk_execute ex4
;
297 exec::bulk_execute(ex4
, handler
, 2);
298 BOOST_ASIO_CHECK(call_count
== 1);
301 exec::bulk_execute(free_bulk_execute(), handler
, 2);
302 BOOST_ASIO_CHECK(call_count
== 1);
307 exec::bulk_execute(ex5
, counting_handler
, 10u),
309 BOOST_ASIO_CHECK(call_count
== 11);
314 exec::bulk_execute(ex6
, counting_handler
, 10u),
316 BOOST_ASIO_CHECK(call_count
== 11);
320 exec::bulk_execute(executor(), counting_handler
, 10u),
322 BOOST_ASIO_CHECK(call_count
== 11);
325 BOOST_ASIO_TEST_SUITE
328 BOOST_ASIO_TEST_CASE(test_can_bulk_execute
)
329 BOOST_ASIO_TEST_CASE(test_bulk_execute
)