early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,68 @@
#
# Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
import feature ;
lib socket ; # SOLARIS, QNXNTO
lib nsl ; # SOLARIS
lib ws2_32 ; # NT
lib mswsock ; # NT
lib ipv6 ; # HPUX
lib network ; # HAIKU
project
: requirements
<library>/boost/date_time//boost_date_time
<library>/boost/system//boost_system
<library>/boost/chrono//boost_chrono
<library>/boost/regex//boost_regex
<define>BOOST_ALL_NO_LIB=1
<threading>multi
<target-os>linux:<define>_XOPEN_SOURCE=600
<target-os>linux:<define>_GNU_SOURCE=1
<target-os>solaris:<define>_XOPEN_SOURCE=500
<target-os>solaris:<define>__EXTENSIONS__
<target-os>solaris:<library>socket
<target-os>solaris:<library>nsl
<target-os>windows:<define>_WIN32_WINNT=0x0501
<target-os>windows,<toolset>cw:<library>ws2_32
<target-os>windows,<toolset>cw:<library>mswsock
<target-os>windows,<toolset>gcc:<library>ws2_32
<target-os>windows,<toolset>gcc:<library>mswsock
<target-os>windows,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
<target-os>hpux,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
<target-os>hpux:<library>ipv6
<target-os>qnxnto:<library>socket
<target-os>haiku:<library>network
;
test-suite "asio" :
[ run any_executor.cpp ]
[ run blocking.cpp ]
[ run blocking_adaptation.cpp ]
[ run bulk_execute.cpp ]
[ run bulk_guarantee.cpp ]
[ run connect.cpp : : : : execution_connect ]
[ run context_as.cpp ]
[ run execute.cpp ]
[ run executor.cpp ]
[ run invocable_archetype.cpp ]
[ run mapping.cpp ]
[ run operation_state.cpp ]
[ run outstanding_work.cpp ]
[ run prefer_only.cpp ]
[ run receiver.cpp ]
[ run relationship.cpp ]
[ run schedule.cpp ]
[ run scheduler.cpp ]
[ run sender.cpp ]
[ run set_done.cpp ]
[ run set_error.cpp ]
[ run set_value.cpp ]
[ run start.cpp ]
[ run submit.cpp ]
;

View File

@@ -0,0 +1,888 @@
//
// any_executor.cpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/any_executor.hpp>
#include <cstring>
#include <boost/asio/thread_pool.hpp>
#include "../unit_test.hpp"
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
using namespace boost::asio;
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif
struct fat_executor
{
fat_executor(int id)
: id_(id)
{
std::memset(data_, 0, sizeof(data_));
}
template <typename F>
void execute(const F&) const
{
}
std::size_t query(execution::occupancy_t) const
{
return 1;
}
friend bool operator==(const fat_executor& a,
const fat_executor& b) BOOST_ASIO_NOEXCEPT
{
return a.id_ == b.id_;
}
friend bool operator!=(const fat_executor& a,
const fat_executor& b) BOOST_ASIO_NOEXCEPT
{
return a.id_ != b.id_;
}
int id_;
unsigned char data_[1024];
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<fat_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <>
struct query_member<fat_executor, execution::occupancy_t>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef std::size_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<fat_executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void increment(int* count)
{
++(*count);
}
void any_executor_construction_test()
{
typedef execution::any_executor<> ex_no_props_t;
typedef execution::any_executor<
execution::blocking_t
> ex_one_prop_t;
typedef execution::any_executor<
execution::blocking_t,
execution::occupancy_t
> ex_two_props_t;
thread_pool pool(1);
boost::asio::nullptr_t null_ptr = boost::asio::nullptr_t();
ex_two_props_t ex_two_props_1;
BOOST_ASIO_CHECK(ex_two_props_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_1 == null_ptr);
ex_two_props_t ex_two_props_2(null_ptr);
BOOST_ASIO_CHECK(ex_two_props_2.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_2 == null_ptr);
BOOST_ASIO_CHECK(ex_two_props_2 == ex_two_props_1);
ex_two_props_t ex_two_props_3(pool.executor());
BOOST_ASIO_CHECK(ex_two_props_3.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_3 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_3 != ex_two_props_1);
ex_two_props_t ex_two_props_4(ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_4 == null_ptr);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_1);
ex_two_props_t ex_two_props_5(ex_two_props_3);
BOOST_ASIO_CHECK(ex_two_props_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_5 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_5 == ex_two_props_3);
ex_two_props_t ex_two_props_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_two_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_6 != ex_two_props_1);
ex_two_props_t ex_two_props_7 = fat_executor(1);
BOOST_ASIO_CHECK(ex_two_props_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_7 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_7 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_7 == ex_two_props_6);
ex_two_props_t ex_two_props_8 = fat_executor(2);
BOOST_ASIO_CHECK(ex_two_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_8 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_8 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_8 != ex_two_props_6);
BOOST_ASIO_CHECK(ex_two_props_8 != ex_two_props_7);
ex_two_props_t ex_two_props_9(ex_two_props_6);
BOOST_ASIO_CHECK(ex_two_props_9.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_9 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_9 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_9 == ex_two_props_6);
BOOST_ASIO_CHECK(ex_two_props_9 == ex_two_props_7);
BOOST_ASIO_CHECK(ex_two_props_9 != ex_two_props_8);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_two_props_t ex_two_props_10(std::move(ex_two_props_1));
BOOST_ASIO_CHECK(ex_two_props_10.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_10 == null_ptr);
BOOST_ASIO_CHECK(ex_two_props_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_1 == null_ptr);
ex_two_props_t ex_two_props_11(std::move(ex_two_props_3));
BOOST_ASIO_CHECK(ex_two_props_11.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_11 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_3 == null_ptr);
BOOST_ASIO_CHECK(ex_two_props_11 == ex_two_props_5);
ex_two_props_t ex_two_props_12(std::move(ex_two_props_7));
BOOST_ASIO_CHECK(ex_two_props_12.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_12 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_7.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_7 == null_ptr);
BOOST_ASIO_CHECK(ex_two_props_12 == ex_two_props_6);
BOOST_ASIO_CHECK(ex_two_props_12 != ex_two_props_8);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_1;
BOOST_ASIO_CHECK(ex_one_prop_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_1 == null_ptr);
ex_one_prop_t ex_one_prop_2(null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_2.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_2 == null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_2 == ex_one_prop_1);
ex_one_prop_t ex_one_prop_3(pool.executor());
BOOST_ASIO_CHECK(ex_one_prop_3.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_3 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_3 != ex_one_prop_1);
ex_one_prop_t ex_one_prop_4(ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_4 == null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_1);
ex_one_prop_t ex_one_prop_5(ex_one_prop_3);
BOOST_ASIO_CHECK(ex_one_prop_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_5 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_5 == ex_one_prop_3);
ex_one_prop_t ex_one_prop_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_one_prop_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_6 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_6 != ex_one_prop_1);
ex_one_prop_t ex_one_prop_7 = fat_executor(1);
BOOST_ASIO_CHECK(ex_one_prop_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_7 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_7 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_7 == ex_one_prop_6);
ex_one_prop_t ex_one_prop_8 = fat_executor(2);
BOOST_ASIO_CHECK(ex_one_prop_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_8 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_8 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_8 != ex_one_prop_6);
BOOST_ASIO_CHECK(ex_one_prop_8 != ex_one_prop_7);
ex_one_prop_t ex_one_prop_9(ex_one_prop_6);
BOOST_ASIO_CHECK(ex_one_prop_9.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_9 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_9 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_9 == ex_one_prop_6);
BOOST_ASIO_CHECK(ex_one_prop_9 == ex_one_prop_7);
BOOST_ASIO_CHECK(ex_one_prop_9 != ex_one_prop_8);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_10(std::move(ex_one_prop_1));
BOOST_ASIO_CHECK(ex_one_prop_10.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_10 == null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_1 == null_ptr);
ex_one_prop_t ex_one_prop_11(std::move(ex_one_prop_3));
BOOST_ASIO_CHECK(ex_one_prop_11.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_11 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_3 == null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_11 == ex_one_prop_5);
ex_one_prop_t ex_one_prop_12(std::move(ex_one_prop_7));
BOOST_ASIO_CHECK(ex_one_prop_12.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_12 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_7.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_7 == null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_12 == ex_one_prop_6);
BOOST_ASIO_CHECK(ex_one_prop_12 != ex_one_prop_8);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_13(ex_two_props_1);
BOOST_ASIO_CHECK(ex_one_prop_13.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_13 == null_ptr);
ex_one_prop_t ex_one_prop_14(ex_two_props_5);
BOOST_ASIO_CHECK(ex_one_prop_14.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_14 != null_ptr);
ex_one_prop_t ex_one_prop_15(ex_two_props_9);
BOOST_ASIO_CHECK(ex_one_prop_15.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_15 != null_ptr);
ex_no_props_t ex_no_props_1;
BOOST_ASIO_CHECK(ex_no_props_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_1 == null_ptr);
ex_no_props_t ex_no_props_2(null_ptr);
BOOST_ASIO_CHECK(ex_no_props_2.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_2 == null_ptr);
BOOST_ASIO_CHECK(ex_no_props_2 == ex_no_props_1);
ex_no_props_t ex_no_props_3(pool.executor());
BOOST_ASIO_CHECK(ex_no_props_3.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_3 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_3 != ex_no_props_1);
ex_no_props_t ex_no_props_4(ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_4 == null_ptr);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_1);
ex_no_props_t ex_no_props_5(ex_no_props_3);
BOOST_ASIO_CHECK(ex_no_props_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_5 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_5 == ex_no_props_3);
ex_no_props_t ex_no_props_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_no_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_6 != ex_no_props_1);
ex_no_props_t ex_no_props_7 = fat_executor(1);
BOOST_ASIO_CHECK(ex_no_props_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_7 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_7 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_7 == ex_no_props_6);
ex_no_props_t ex_no_props_8 = fat_executor(2);
BOOST_ASIO_CHECK(ex_no_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_8 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_8 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_8 != ex_no_props_6);
BOOST_ASIO_CHECK(ex_no_props_8 != ex_no_props_7);
ex_no_props_t ex_no_props_9(ex_no_props_6);
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_9 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_9 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_9 == ex_no_props_6);
BOOST_ASIO_CHECK(ex_no_props_9 == ex_no_props_7);
BOOST_ASIO_CHECK(ex_no_props_9 != ex_no_props_8);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_no_props_t ex_no_props_10(std::move(ex_no_props_1));
BOOST_ASIO_CHECK(ex_no_props_10.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_10 == null_ptr);
BOOST_ASIO_CHECK(ex_no_props_1.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_1 == null_ptr);
ex_no_props_t ex_no_props_11(std::move(ex_no_props_3));
BOOST_ASIO_CHECK(ex_no_props_11.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_11 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_3 == null_ptr);
BOOST_ASIO_CHECK(ex_no_props_11 == ex_no_props_5);
ex_no_props_t ex_no_props_12(std::move(ex_no_props_7));
BOOST_ASIO_CHECK(ex_no_props_12.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_12 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_7.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_7 == null_ptr);
BOOST_ASIO_CHECK(ex_no_props_12 == ex_no_props_6);
BOOST_ASIO_CHECK(ex_no_props_12 != ex_no_props_8);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_no_props_t ex_no_props_13(ex_two_props_1);
BOOST_ASIO_CHECK(ex_no_props_13.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_13 == null_ptr);
ex_no_props_t ex_no_props_14(ex_two_props_5);
BOOST_ASIO_CHECK(ex_no_props_14.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_14 != null_ptr);
ex_no_props_t ex_no_props_15(ex_two_props_9);
BOOST_ASIO_CHECK(ex_no_props_15.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_15 != null_ptr);
ex_no_props_t ex_no_props_16(ex_one_prop_1);
BOOST_ASIO_CHECK(ex_no_props_16.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_16 == null_ptr);
ex_no_props_t ex_no_props_17(ex_one_prop_5);
BOOST_ASIO_CHECK(ex_no_props_17.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_17 != null_ptr);
ex_no_props_t ex_no_props_18(ex_one_prop_9);
BOOST_ASIO_CHECK(ex_no_props_18.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_18 != null_ptr);
}
void any_executor_assignment_test()
{
typedef execution::any_executor<> ex_no_props_t;
typedef execution::any_executor<
execution::blocking_t
> ex_one_prop_t;
typedef execution::any_executor<
execution::blocking_t,
execution::occupancy_t
> ex_two_props_t;
thread_pool pool(1);
boost::asio::nullptr_t null_ptr = boost::asio::nullptr_t();
ex_two_props_t ex_two_props_1;
ex_two_props_t ex_two_props_2;
ex_two_props_2 = null_ptr;
BOOST_ASIO_CHECK(ex_two_props_2.target<void>() == 0);
ex_two_props_t ex_two_props_3;
ex_two_props_3 = pool.executor();
BOOST_ASIO_CHECK(ex_two_props_3.target<void>() != 0);
ex_two_props_t ex_two_props_4;
ex_two_props_4 = ex_two_props_1;
BOOST_ASIO_CHECK(ex_two_props_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_1);
ex_two_props_4 = ex_two_props_3;
BOOST_ASIO_CHECK(ex_two_props_4.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_3);
ex_two_props_t ex_two_props_5;
ex_two_props_5 = fat_executor(1);
BOOST_ASIO_CHECK(ex_two_props_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_5 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_5 != ex_two_props_1);
ex_two_props_t ex_two_props_6;
ex_two_props_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_two_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_6 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_6 == ex_two_props_5);
ex_two_props_6 = fat_executor(2);
BOOST_ASIO_CHECK(ex_two_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_6 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_6 != ex_two_props_5);
ex_two_props_t ex_two_props_7;
ex_two_props_7 = ex_two_props_5;
BOOST_ASIO_CHECK(ex_two_props_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_7 != null_ptr);
BOOST_ASIO_CHECK(ex_two_props_7 != ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_7 == ex_two_props_5);
BOOST_ASIO_CHECK(ex_two_props_7 != ex_two_props_6);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_two_props_t ex_two_props_8;
ex_two_props_8 = std::move(ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_8.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_1.target<void>() == 0);
ex_two_props_8 = std::move(ex_two_props_3);
BOOST_ASIO_CHECK(ex_two_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_8 == ex_two_props_4);
ex_two_props_8 = std::move(ex_two_props_5);
BOOST_ASIO_CHECK(ex_two_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_two_props_5.target<void>() == 0);
BOOST_ASIO_CHECK(ex_two_props_8 == ex_two_props_7);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_1;
ex_one_prop_t ex_one_prop_2;
ex_one_prop_2 = null_ptr;
BOOST_ASIO_CHECK(ex_one_prop_2.target<void>() == 0);
ex_one_prop_t ex_one_prop_3;
ex_one_prop_3 = pool.executor();
BOOST_ASIO_CHECK(ex_one_prop_3.target<void>() != 0);
ex_one_prop_t ex_one_prop_4;
ex_one_prop_4 = ex_one_prop_1;
BOOST_ASIO_CHECK(ex_one_prop_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_1);
ex_one_prop_4 = ex_one_prop_3;
BOOST_ASIO_CHECK(ex_one_prop_4.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_3);
ex_one_prop_t ex_one_prop_5;
ex_one_prop_5 = fat_executor(1);
BOOST_ASIO_CHECK(ex_one_prop_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_5 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_5 != ex_one_prop_1);
ex_one_prop_t ex_one_prop_6;
ex_one_prop_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_one_prop_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_6 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_6 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_6 == ex_one_prop_5);
ex_one_prop_6 = fat_executor(2);
BOOST_ASIO_CHECK(ex_one_prop_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_6 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_6 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_6 != ex_one_prop_5);
ex_one_prop_t ex_one_prop_7;
ex_one_prop_7 = ex_one_prop_5;
BOOST_ASIO_CHECK(ex_one_prop_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_7 != null_ptr);
BOOST_ASIO_CHECK(ex_one_prop_7 != ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_7 == ex_one_prop_5);
BOOST_ASIO_CHECK(ex_one_prop_7 != ex_one_prop_6);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_8;
ex_one_prop_8 = std::move(ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_8.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_1.target<void>() == 0);
ex_one_prop_8 = std::move(ex_one_prop_3);
BOOST_ASIO_CHECK(ex_one_prop_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_8 == ex_one_prop_4);
ex_one_prop_8 = std::move(ex_one_prop_5);
BOOST_ASIO_CHECK(ex_one_prop_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_one_prop_5.target<void>() == 0);
BOOST_ASIO_CHECK(ex_one_prop_8 == ex_one_prop_7);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_one_prop_t ex_one_prop_9;
ex_one_prop_9 = ex_two_props_1;
BOOST_ASIO_CHECK(ex_one_prop_9.target<void>() == 0);
ex_one_prop_9 = ex_two_props_4;
BOOST_ASIO_CHECK(ex_one_prop_9.target<void>() != 0);
ex_one_prop_9 = ex_two_props_7;
BOOST_ASIO_CHECK(ex_one_prop_9.target<void>() != 0);
ex_no_props_t ex_no_props_1;
ex_no_props_t ex_no_props_2;
ex_no_props_2 = null_ptr;
BOOST_ASIO_CHECK(ex_no_props_2.target<void>() == 0);
ex_no_props_t ex_no_props_3;
ex_no_props_3 = pool.executor();
BOOST_ASIO_CHECK(ex_no_props_3.target<void>() != 0);
ex_no_props_t ex_no_props_4;
ex_no_props_4 = ex_no_props_1;
BOOST_ASIO_CHECK(ex_no_props_4.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_1);
ex_no_props_4 = ex_no_props_3;
BOOST_ASIO_CHECK(ex_no_props_4.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_3);
ex_no_props_t ex_no_props_5;
ex_no_props_5 = fat_executor(1);
BOOST_ASIO_CHECK(ex_no_props_5.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_5 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_5 != ex_no_props_1);
ex_no_props_t ex_no_props_6;
ex_no_props_6 = fat_executor(1);
BOOST_ASIO_CHECK(ex_no_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_6 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_6 == ex_no_props_5);
ex_no_props_6 = fat_executor(2);
BOOST_ASIO_CHECK(ex_no_props_6.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_6 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_6 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_6 != ex_no_props_5);
ex_no_props_t ex_no_props_7;
ex_no_props_7 = ex_no_props_5;
BOOST_ASIO_CHECK(ex_no_props_7.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_7 != null_ptr);
BOOST_ASIO_CHECK(ex_no_props_7 != ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_7 == ex_no_props_5);
BOOST_ASIO_CHECK(ex_no_props_7 != ex_no_props_6);
#if defined(BOOST_ASIO_HAS_MOVE)
ex_no_props_t ex_no_props_8;
ex_no_props_8 = std::move(ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_8.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_1.target<void>() == 0);
ex_no_props_8 = std::move(ex_no_props_3);
BOOST_ASIO_CHECK(ex_no_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_3.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_8 == ex_no_props_4);
ex_no_props_8 = std::move(ex_no_props_5);
BOOST_ASIO_CHECK(ex_no_props_8.target<void>() != 0);
BOOST_ASIO_CHECK(ex_no_props_5.target<void>() == 0);
BOOST_ASIO_CHECK(ex_no_props_8 == ex_no_props_7);
#endif // defined(BOOST_ASIO_HAS_MOVE)
ex_no_props_t ex_no_props_9;
ex_no_props_9 = ex_two_props_1;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() == 0);
ex_no_props_9 = ex_two_props_4;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() != 0);
ex_no_props_9 = ex_two_props_7;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() != 0);
ex_no_props_9 = ex_one_prop_1;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() == 0);
ex_no_props_9 = ex_one_prop_4;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() != 0);
ex_no_props_9 = ex_one_prop_7;
BOOST_ASIO_CHECK(ex_no_props_9.target<void>() != 0);
}
void any_executor_swap_test()
{
typedef execution::any_executor<> ex_no_props_t;
typedef execution::any_executor<
execution::blocking_t
> ex_one_prop_t;
typedef execution::any_executor<
execution::blocking_t,
execution::occupancy_t
> ex_two_props_t;
thread_pool pool1(1);
thread_pool pool2(1);
ex_no_props_t ex_no_props_1(pool1.executor());
ex_no_props_t ex_no_props_2(pool2.executor());
ex_no_props_t ex_no_props_3(ex_no_props_1);
ex_no_props_t ex_no_props_4(ex_no_props_2);
BOOST_ASIO_CHECK(ex_no_props_3 == ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_2);
ex_no_props_3.swap(ex_no_props_4);
BOOST_ASIO_CHECK(ex_no_props_3 == ex_no_props_2);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_1);
execution::swap(ex_no_props_3, ex_no_props_4);
BOOST_ASIO_CHECK(ex_no_props_3 == ex_no_props_1);
BOOST_ASIO_CHECK(ex_no_props_4 == ex_no_props_2);
ex_one_prop_t ex_one_prop_1(pool1.executor());
ex_one_prop_t ex_one_prop_2(pool2.executor());
ex_one_prop_t ex_one_prop_3(ex_one_prop_1);
ex_one_prop_t ex_one_prop_4(ex_one_prop_2);
BOOST_ASIO_CHECK(ex_one_prop_3 == ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_2);
ex_one_prop_3.swap(ex_one_prop_4);
BOOST_ASIO_CHECK(ex_one_prop_3 == ex_one_prop_2);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_1);
execution::swap(ex_one_prop_3, ex_one_prop_4);
BOOST_ASIO_CHECK(ex_one_prop_3 == ex_one_prop_1);
BOOST_ASIO_CHECK(ex_one_prop_4 == ex_one_prop_2);
ex_two_props_t ex_two_props_1(pool1.executor());
ex_two_props_t ex_two_props_2(pool2.executor());
ex_two_props_t ex_two_props_3(ex_two_props_1);
ex_two_props_t ex_two_props_4(ex_two_props_2);
BOOST_ASIO_CHECK(ex_two_props_3 == ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_2);
ex_two_props_3.swap(ex_two_props_4);
BOOST_ASIO_CHECK(ex_two_props_3 == ex_two_props_2);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_1);
execution::swap(ex_two_props_3, ex_two_props_4);
BOOST_ASIO_CHECK(ex_two_props_3 == ex_two_props_1);
BOOST_ASIO_CHECK(ex_two_props_4 == ex_two_props_2);
}
void any_executor_query_test()
{
thread_pool pool(1);
execution::any_executor<
execution::blocking_t,
execution::outstanding_work_t,
execution::relationship_t,
execution::mapping_t::thread_t,
execution::occupancy_t>
ex(pool.executor());
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::blocking)
== boost::asio::execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::blocking.possibly)
== boost::asio::execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::outstanding_work)
== boost::asio::execution::outstanding_work.untracked);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::outstanding_work.untracked)
== boost::asio::execution::outstanding_work.untracked);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::relationship)
== boost::asio::execution::relationship.fork);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::relationship.fork)
== boost::asio::execution::relationship.fork);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::mapping)
== boost::asio::execution::mapping.thread);
BOOST_ASIO_CHECK(
boost::asio::query(ex, boost::asio::execution::occupancy)
== 1);
}
void any_executor_execute_test()
{
int count = 0;
thread_pool pool(1);
execution::any_executor<
execution::blocking_t::possibly_t,
execution::blocking_t::never_t,
execution::outstanding_work_t::untracked_t,
execution::outstanding_work_t::tracked_t,
execution::relationship_t::continuation_t>
ex(pool.executor());
boost::asio::execution::execute(pool.executor(),
bindns::bind(increment, &count));
boost::asio::execution::execute(
boost::asio::require(pool.executor(),
boost::asio::execution::blocking.possibly),
bindns::bind(increment, &count));
boost::asio::execution::execute(
boost::asio::require(pool.executor(),
boost::asio::execution::blocking.never),
bindns::bind(increment, &count));
boost::asio::execution::execute(
boost::asio::require(pool.executor(),
boost::asio::execution::blocking.never,
boost::asio::execution::outstanding_work.tracked),
bindns::bind(increment, &count));
boost::asio::execution::execute(
boost::asio::require(pool.executor(),
boost::asio::execution::blocking.never,
boost::asio::execution::outstanding_work.untracked),
bindns::bind(increment, &count));
boost::asio::execution::execute(
boost::asio::require(pool.executor(),
boost::asio::execution::blocking.never,
boost::asio::execution::outstanding_work.untracked,
boost::asio::execution::relationship.continuation),
bindns::bind(increment, &count));
pool.wait();
BOOST_ASIO_CHECK(count == 6);
}
BOOST_ASIO_TEST_SUITE
(
"any_executor",
BOOST_ASIO_TEST_CASE(any_executor_construction_test)
BOOST_ASIO_TEST_CASE(any_executor_assignment_test)
BOOST_ASIO_TEST_CASE(any_executor_swap_test)
BOOST_ASIO_TEST_CASE(any_executor_query_test)
BOOST_ASIO_TEST_CASE(any_executor_execute_test)
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,330 @@
//
// bulk_execute.cpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/bulk_execute.hpp>
#include <boost/asio/execution.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
int call_count = 0;
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct sender : exec::sender_base
{
sender()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
return operation_state();
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<const sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct no_bulk_execute
{
};
struct const_member_bulk_execute
{
const_member_bulk_execute()
{
}
template <typename F>
sender bulk_execute(BOOST_ASIO_MOVE_ARG(F), std::size_t) const
{
++call_count;
return sender();
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
template <typename F, typename N>
struct bulk_execute_member<const const_member_bulk_execute, F, N>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef sender result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct free_bulk_execute
{
free_bulk_execute()
{
}
template <typename F>
friend sender bulk_execute(const free_bulk_execute&,
BOOST_ASIO_MOVE_ARG(F), std::size_t)
{
++call_count;
return sender();
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
template <typename F, typename N>
struct bulk_execute_free<const free_bulk_execute, F, N>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef sender result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_can_bulk_execute()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_bulk_execute<
no_bulk_execute&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_bulk_execute<
const no_bulk_execute&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_bulk_execute<
const_member_bulk_execute&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_bulk_execute<
const const_member_bulk_execute&,
exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_bulk_execute<
free_bulk_execute&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_bulk_execute<
const free_bulk_execute&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b6 == true);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_bulk_execute<
executor&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_bulk_execute<
const executor&, exec::invocable_archetype, std::size_t>::value;
BOOST_ASIO_CHECK(b8 == true);
}
void handler(std::size_t)
{
}
void counting_handler(std::size_t)
{
++call_count;
}
void completion_handler()
{
++call_count;
}
void test_bulk_execute()
{
call_count = 0;
const_member_bulk_execute ex1;
exec::bulk_execute(ex1, handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_bulk_execute ex2;
exec::bulk_execute(ex2, handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::bulk_execute(const_member_bulk_execute(), handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_bulk_execute ex3;
exec::bulk_execute(ex3, handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_bulk_execute ex4;
exec::bulk_execute(ex4, handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::bulk_execute(free_bulk_execute(), handler, 2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
executor ex5;
exec::execute(
exec::bulk_execute(ex5, counting_handler, 10u),
completion_handler);
BOOST_ASIO_CHECK(call_count == 11);
call_count = 0;
const executor ex6;
exec::execute(
exec::bulk_execute(ex6, counting_handler, 10u),
completion_handler);
BOOST_ASIO_CHECK(call_count == 11);
call_count = 0;
exec::execute(
exec::bulk_execute(executor(), counting_handler, 10u),
completion_handler);
BOOST_ASIO_CHECK(call_count == 11);
}
BOOST_ASIO_TEST_SUITE
(
"bulk_execute",
BOOST_ASIO_TEST_CASE(test_can_bulk_execute)
BOOST_ASIO_TEST_CASE(test_bulk_execute)
)

View File

@@ -0,0 +1,497 @@
//
// connect.cpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/connect.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct no_connect_1
{
};
struct no_connect_2 : exec::sender_base
{
};
struct no_connect_3
{
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
return operation_state();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct connect_member<no_connect_3, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
struct const_member_connect : exec::sender_base
{
const_member_connect()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
++call_count;
return operation_state();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct connect_member<const const_member_connect, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
struct free_connect_const_receiver : exec::sender_base
{
free_connect_const_receiver()
{
}
template <typename R>
friend operation_state connect(
const free_connect_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
return operation_state();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct connect_free<const free_connect_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
struct non_const_member_connect : exec::sender_base
{
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
return operation_state();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct connect_member<non_const_member_connect, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
struct free_connect_non_const_receiver : exec::sender_base
{
free_connect_non_const_receiver()
{
}
template <typename R>
friend operation_state connect(
free_connect_non_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
return operation_state();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct connect_free<free_connect_non_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
struct receiver
{
receiver()
{
}
receiver(const receiver&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver(receiver&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
(void)f;
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_can_connect()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_connect<
no_connect_1&, receiver>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_connect<
const no_connect_1&, receiver>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_connect<
no_connect_2&, receiver>::value;
BOOST_ASIO_CHECK(b3 == false);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_connect<
const no_connect_2&, receiver>::value;
BOOST_ASIO_CHECK(b4 == false);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_connect<
no_connect_3&, receiver>::value;
BOOST_ASIO_CHECK(b5 == false);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_connect<
const no_connect_3&, receiver>::value;
BOOST_ASIO_CHECK(b6 == false);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_connect<
const_member_connect&, receiver>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_connect<
const const_member_connect&, receiver>::value;
BOOST_ASIO_CHECK(b8 == true);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_connect<
free_connect_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_connect<
const free_connect_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b10 == true);
BOOST_ASIO_CONSTEXPR bool b11 = exec::can_connect<
non_const_member_connect&, receiver>::value;
BOOST_ASIO_CHECK(b11 == true);
BOOST_ASIO_CONSTEXPR bool b12 = exec::can_connect<
const non_const_member_connect&, receiver>::value;
BOOST_ASIO_CHECK(b12 == false);
BOOST_ASIO_CONSTEXPR bool b13 = exec::can_connect<
free_connect_non_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b13 == true);
BOOST_ASIO_CONSTEXPR bool b14 = exec::can_connect<
const free_connect_non_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b14 == false);
BOOST_ASIO_CONSTEXPR bool b15 = exec::can_connect<
executor&, receiver>::value;
BOOST_ASIO_CHECK(b15 == true);
BOOST_ASIO_CONSTEXPR bool b16 = exec::can_connect<
const executor&, receiver>::value;
BOOST_ASIO_CHECK(b16 == true);
}
void increment(int* count)
{
++(*count);
}
void test_connect()
{
receiver r;
call_count = 0;
const_member_connect s1;
operation_state o1 = exec::connect(s1, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o1;
call_count = 0;
const const_member_connect s2;
operation_state o2 = exec::connect(s2, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o2;
call_count = 0;
operation_state o3 = exec::connect(const_member_connect(), r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o3;
call_count = 0;
free_connect_const_receiver s3;
operation_state o4 = exec::connect(s3, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o4;
call_count = 0;
const free_connect_const_receiver s4;
operation_state o5 = exec::connect(s4, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o5;
call_count = 0;
operation_state o6 = exec::connect(free_connect_const_receiver(), r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o6;
call_count = 0;
non_const_member_connect s5;
operation_state o7 = exec::connect(s5, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o7;
call_count = 0;
free_connect_non_const_receiver s6;
operation_state o8 = exec::connect(s6, r);
BOOST_ASIO_CHECK(call_count == 1);
(void)o8;
executor s7;
exec::connect_result<executor&,
receiver&>::type o9 = exec::connect(s7, r);
BOOST_ASIO_CHECK((
exec::is_operation_state<
exec::connect_result<executor&, receiver&>::type
>::value));
(void)o9;
const executor s8;
exec::connect_result<const executor&,
receiver&>::type o10 = exec::connect(s8, r);
(void)exec::connect(s8, r);
BOOST_ASIO_CHECK((
exec::is_operation_state<
exec::connect_result<const executor&, receiver&>::type
>::value));
(void)o10;
}
BOOST_ASIO_TEST_SUITE
(
"connect",
BOOST_ASIO_TEST_CASE(test_can_connect)
BOOST_ASIO_TEST_CASE(test_connect)
)

View File

@@ -0,0 +1,157 @@
//
// context_as.cpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/context_as.hpp>
#include <boost/asio/execution/any_executor.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/static_thread_pool.hpp>
#include "../unit_test.hpp"
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
using namespace boost::asio;
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif
void context_as_executor_query_test()
{
static_thread_pool pool(1);
BOOST_ASIO_CHECK(
&boost::asio::query(pool.executor(),
execution::context_as_t<static_thread_pool&>())
== &pool);
execution::any_executor<
execution::context_as_t<static_thread_pool&>
> ex1 = pool.executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex1,
execution::context_as_t<static_thread_pool&>())
== &pool);
BOOST_ASIO_CHECK(
&boost::asio::query(ex1, execution::context)
== &pool);
BOOST_ASIO_CHECK(
&boost::asio::query(pool.executor(),
execution::context_as_t<const static_thread_pool&>())
== &pool);
execution::any_executor<
execution::context_as_t<const static_thread_pool&>
> ex2 = pool.executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex2,
execution::context_as_t<const static_thread_pool&>())
== &pool);
BOOST_ASIO_CHECK(
&boost::asio::query(ex2, execution::context)
== &pool);
io_context io_ctx;
BOOST_ASIO_CHECK(
&boost::asio::query(io_ctx.get_executor(),
execution::context_as_t<io_context&>())
== &io_ctx);
execution::any_executor<
execution::context_as_t<io_context&>
> ex3 = io_ctx.get_executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex3,
execution::context_as_t<io_context&>())
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(ex3, execution::context)
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(io_ctx.get_executor(),
execution::context_as_t<const io_context&>())
== &io_ctx);
execution::any_executor<
execution::context_as_t<const io_context&>
> ex4 = io_ctx.get_executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex4,
execution::context_as_t<const io_context&>())
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(ex4, execution::context)
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(io_ctx.get_executor(),
execution::context_as_t<execution_context&>())
== &io_ctx);
execution::any_executor<
execution::context_as_t<execution_context&>
> ex5 = io_ctx.get_executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex5,
execution::context_as_t<execution_context&>())
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(ex5, execution::context)
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(io_ctx.get_executor(),
execution::context_as_t<const execution_context&>())
== &io_ctx);
execution::any_executor<
execution::context_as_t<const execution_context&>
> ex6 = io_ctx.get_executor();
BOOST_ASIO_CHECK(
&boost::asio::query(ex6,
execution::context_as_t<const execution_context&>())
== &io_ctx);
BOOST_ASIO_CHECK(
&boost::asio::query(ex6, execution::context)
== &io_ctx);
}
BOOST_ASIO_TEST_SUITE
(
"context_as",
BOOST_ASIO_TEST_CASE(context_as_executor_query_test)
)

View File

@@ -0,0 +1,400 @@
//
// execute.cpp
// ~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/execute.hpp>
#include <boost/asio/execution/sender.hpp>
#include <boost/asio/execution/submit.hpp>
#include <boost/asio/execution/invocable_archetype.hpp>
#include "../unit_test.hpp"
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace exec = boost::asio::execution;
struct no_execute
{
};
struct const_member_execute
{
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename F>
struct execute_member<const_member_execute, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
struct free_execute_const_executor
{
template <typename F>
friend void execute(const free_execute_const_executor&,
BOOST_ASIO_MOVE_ARG(F) f)
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename F>
struct execute_free<free_execute_const_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
#if defined(BOOST_ASIO_HAS_MOVE)
// Support for rvalue references is required in order to use the execute
// customisation point with non-const member functions and free functions
// taking non-const arguments.
struct non_const_member_execute
{
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f)
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename F>
struct execute_member<non_const_member_execute, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
template <typename F>
struct execute_member<const non_const_member_execute, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
template <typename F>
struct execute_member<const non_const_member_execute&, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
struct free_execute_non_const_executor
{
template <typename F>
friend void execute(free_execute_non_const_executor&,
BOOST_ASIO_MOVE_ARG(F) f)
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename F>
struct execute_free<free_execute_non_const_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
template <typename F>
struct execute_free<const free_execute_non_const_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
template <typename F>
struct execute_free<const free_execute_non_const_executor&, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
#endif // defined(BOOST_ASIO_HAS_MOVE)
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct sender : exec::sender_base
{
sender()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
return operation_state();
}
template <typename R>
void submit(BOOST_ASIO_MOVE_ARG(R) r) const
{
exec::set_value(BOOST_ASIO_MOVE_CAST(R)(r));
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<const sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
template <typename R>
struct submit_member<const sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_can_execute()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_execute<
no_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_execute<
const no_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_execute<
const_member_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_execute<
const const_member_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_execute<
free_execute_const_executor&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_execute<
const free_execute_const_executor&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b6 == true);
#if defined(BOOST_ASIO_HAS_MOVE)
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_execute<
non_const_member_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_execute<
const non_const_member_execute&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b8 == false);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_execute<
free_execute_non_const_executor&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_execute<
const free_execute_non_const_executor&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b10 == false);
#endif // defined(BOOST_ASIO_HAS_MOVE)
BOOST_ASIO_CONSTEXPR bool b11 = exec::can_execute<
sender&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b11 == true);
BOOST_ASIO_CONSTEXPR bool b12 = exec::can_execute<
const sender&, exec::invocable_archetype>::value;
BOOST_ASIO_CHECK(b12 == true);
}
void increment(int* count)
{
++(*count);
}
void test_execute()
{
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
int count = 0;
const_member_execute ex1 = {};
exec::execute(ex1, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const const_member_execute ex2 = {};
exec::execute(ex2, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
exec::execute(const_member_execute(), bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
free_execute_const_executor ex3 = {};
exec::execute(ex3, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const free_execute_const_executor ex4 = {};
exec::execute(ex4, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
exec::execute(free_execute_const_executor(),
bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
#if defined(BOOST_ASIO_HAS_MOVE)
count = 0;
non_const_member_execute ex5 = {};
exec::execute(ex5, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
free_execute_non_const_executor ex6 = {};
exec::execute(ex6, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
#endif // defined(BOOST_ASIO_HAS_MOVE)
count = 0;
sender ex7;
exec::execute(ex3, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const sender ex8;
exec::execute(ex4, bindns::bind(&increment, &count));
BOOST_ASIO_CHECK(count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"blocking",
BOOST_ASIO_TEST_CASE(test_can_execute)
BOOST_ASIO_TEST_CASE(test_execute)
)

View File

@@ -0,0 +1,186 @@
//
// executor.cpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/executor.hpp>
#include "../unit_test.hpp"
struct not_an_executor
{
};
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
(void)f;
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void is_executor_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_executor<
void
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_executor<
not_an_executor
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_executor<
executor
>::value));
}
void is_executor_of_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_executor_of<
void,
void(*)()
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_executor_of<
not_an_executor,
void(*)()
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_executor_of<
executor,
void(*)()
>::value));
}
struct executor_with_other_shape_type
{
typedef double shape_type;
};
void executor_shape_test()
{
BOOST_ASIO_CHECK((
boost::asio::is_same<
boost::asio::execution::executor_shape<executor>::type,
std::size_t
>::value));
BOOST_ASIO_CHECK((
boost::asio::is_same<
boost::asio::execution::executor_shape<
executor_with_other_shape_type
>::type,
double
>::value));
}
struct executor_with_other_index_type
{
typedef unsigned char index_type;
};
void executor_index_test()
{
BOOST_ASIO_CHECK((
boost::asio::is_same<
boost::asio::execution::executor_index<executor>::type,
std::size_t
>::value));
BOOST_ASIO_CHECK((
boost::asio::is_same<
boost::asio::execution::executor_index<
executor_with_other_shape_type
>::type,
double
>::value));
BOOST_ASIO_CHECK((
boost::asio::is_same<
boost::asio::execution::executor_index<
executor_with_other_index_type
>::type,
unsigned char
>::value));
}
BOOST_ASIO_TEST_SUITE
(
"executor",
BOOST_ASIO_TEST_CASE(is_executor_test)
BOOST_ASIO_TEST_CASE(is_executor_of_test)
BOOST_ASIO_TEST_CASE(executor_shape_test)
BOOST_ASIO_TEST_CASE(executor_index_test)
)

View File

@@ -0,0 +1,25 @@
//
// invocable_archetype.cpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/invocable_archetype.hpp>
#include "../unit_test.hpp"
BOOST_ASIO_TEST_SUITE
(
"invocable_archetype",
BOOST_ASIO_TEST_CASE(null_test)
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,108 @@
//
// operation_state.cpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/operation_state.hpp>
#include <string>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
struct not_an_operation_state_1
{
};
struct not_an_operation_state_2
{
void start()
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<not_an_operation_state_2>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void is_operation_state_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_operation_state<
void
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_operation_state<
not_an_operation_state_1
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_operation_state<
not_an_operation_state_2
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_operation_state<
operation_state
>::value));
}
BOOST_ASIO_TEST_SUITE
(
"operation_state",
BOOST_ASIO_TEST_CASE(is_operation_state_test)
)

View File

@@ -0,0 +1,549 @@
//
// prefer_only.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/prefer_only.hpp>
#include <boost/asio/execution/any_executor.hpp>
#include "../unit_test.hpp"
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
using namespace boost::asio;
#if defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif
static int possibly_blocking_count = 0;
static int never_blocking_count = 0;
struct possibly_blocking_executor
{
template <typename F>
void execute(const F&) const
{
++possibly_blocking_count;
}
friend bool operator==(const possibly_blocking_executor&,
const possibly_blocking_executor&) BOOST_ASIO_NOEXCEPT
{
return true;
}
friend bool operator!=(const possibly_blocking_executor&,
const possibly_blocking_executor&) BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<possibly_blocking_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<possibly_blocking_executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct never_blocking_executor
{
static BOOST_ASIO_CONSTEXPR execution::blocking_t::never_t
query(execution::blocking_t) BOOST_ASIO_NOEXCEPT
{
return execution::blocking_t::never_t();
}
template <typename F>
void execute(const F&) const
{
++never_blocking_count;
}
friend bool operator==(const never_blocking_executor&,
const never_blocking_executor&) BOOST_ASIO_NOEXCEPT
{
return true;
}
friend bool operator!=(const never_blocking_executor&,
const never_blocking_executor&) BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<never_blocking_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<never_blocking_executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
template <typename Param>
struct query_static_constexpr_member<
never_blocking_executor, Param,
typename boost::asio::enable_if<
boost::asio::is_convertible<Param, execution::blocking_t>::value
>::type>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef execution::blocking_t::never_t result_type;
static BOOST_ASIO_CONSTEXPR result_type value()
{
return result_type();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct either_blocking_executor
{
execution::blocking_t blocking_;
explicit either_blocking_executor(execution::blocking_t b)
: blocking_(b)
{
}
execution::blocking_t query(execution::blocking_t) const BOOST_ASIO_NOEXCEPT
{
return blocking_;
}
either_blocking_executor require(execution::blocking_t::possibly_t) const
{
return either_blocking_executor(execution::blocking.possibly);
}
either_blocking_executor require(execution::blocking_t::never_t) const
{
return either_blocking_executor(execution::blocking.never);
}
template <typename F>
void execute(const F&) const
{
if (blocking_ == execution::blocking.never)
++never_blocking_count;
else
++possibly_blocking_count;
}
friend bool operator==(const either_blocking_executor& a,
const either_blocking_executor& b) BOOST_ASIO_NOEXCEPT
{
return a.blocking_ == b.blocking_;
}
friend bool operator!=(const either_blocking_executor& a,
const either_blocking_executor& b) BOOST_ASIO_NOEXCEPT
{
return a.blocking_ != b.blocking_;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<either_blocking_executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<either_blocking_executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Param>
struct query_member<
either_blocking_executor, Param,
typename boost::asio::enable_if<
boost::asio::is_convertible<Param, execution::blocking_t>::value
>::type>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef execution::blocking_t result_type;
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Param>
struct require_member<
either_blocking_executor, Param,
typename boost::asio::enable_if<
boost::asio::is_convertible<Param, execution::blocking_t>::value
>::type>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef either_blocking_executor result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void prefer_only_executor_query_test()
{
typedef execution::any_executor<
execution::blocking_t,
execution::prefer_only<execution::blocking_t::possibly_t>,
execution::prefer_only<execution::blocking_t::never_t>
> executor_type;
executor_type ex1 = possibly_blocking_executor();
BOOST_ASIO_CHECK(
boost::asio::query(ex1, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex1, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex1, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex2 = boost::asio::prefer(ex1, execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex2, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex2, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex2, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex3 = boost::asio::prefer(ex1, execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex3, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex3, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex3, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex4 = never_blocking_executor();
BOOST_ASIO_CHECK(
boost::asio::query(ex4, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex4, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex4, execution::blocking.never)
== execution::blocking.never);
executor_type ex5 = boost::asio::prefer(ex4, execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex5, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex5, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex5, execution::blocking.never)
== execution::blocking.never);
executor_type ex6 = boost::asio::prefer(ex4, execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex6, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex6, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex6, execution::blocking.never)
== execution::blocking.never);
executor_type ex7 = either_blocking_executor(execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex7, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex7, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex7, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex8 = boost::asio::prefer(ex7, execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex8, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex8, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex8, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex9 = boost::asio::prefer(ex7, execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex9, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex9, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex9, execution::blocking.never)
== execution::blocking.never);
executor_type ex10 = either_blocking_executor(execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex10, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex10, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex10, execution::blocking.never)
== execution::blocking.never);
executor_type ex11 = boost::asio::prefer(ex7, execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex11, execution::blocking)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex11, execution::blocking.possibly)
== execution::blocking.possibly);
BOOST_ASIO_CHECK(
boost::asio::query(ex11, execution::blocking.never)
== execution::blocking.possibly);
executor_type ex12 = boost::asio::prefer(ex7, execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex12, execution::blocking)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex12, execution::blocking.possibly)
== execution::blocking.never);
BOOST_ASIO_CHECK(
boost::asio::query(ex12, execution::blocking.never)
== execution::blocking.never);
}
void do_nothing()
{
}
void prefer_only_executor_execute_test()
{
typedef execution::any_executor<
execution::blocking_t,
execution::prefer_only<execution::blocking_t::possibly_t>,
execution::prefer_only<execution::blocking_t::never_t>
> executor_type;
executor_type ex1 = possibly_blocking_executor();
execution::execute(ex1, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 1);
BOOST_ASIO_CHECK(never_blocking_count == 0);
executor_type ex2 = boost::asio::prefer(ex1, execution::blocking.possibly);
execution::execute(ex2, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 2);
BOOST_ASIO_CHECK(never_blocking_count == 0);
executor_type ex3 = boost::asio::prefer(ex1, execution::blocking.never);
execution::execute(ex3, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 3);
BOOST_ASIO_CHECK(never_blocking_count == 0);
executor_type ex4 = never_blocking_executor();
execution::execute(ex4, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 3);
BOOST_ASIO_CHECK(never_blocking_count == 1);
executor_type ex5 = boost::asio::prefer(ex4, execution::blocking.possibly);
execution::execute(ex5, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 3);
BOOST_ASIO_CHECK(never_blocking_count == 2);
executor_type ex6 = boost::asio::prefer(ex4, execution::blocking.never);
execution::execute(ex6, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 3);
BOOST_ASIO_CHECK(never_blocking_count == 3);
executor_type ex7 = either_blocking_executor(execution::blocking.possibly);
execution::execute(ex7, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 4);
BOOST_ASIO_CHECK(never_blocking_count == 3);
executor_type ex8 = boost::asio::prefer(ex7, execution::blocking.possibly);
execution::execute(ex8, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 5);
BOOST_ASIO_CHECK(never_blocking_count == 3);
executor_type ex9 = boost::asio::prefer(ex7, execution::blocking.never);
execution::execute(ex9, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 5);
BOOST_ASIO_CHECK(never_blocking_count == 4);
executor_type ex10 = either_blocking_executor(execution::blocking.never);
execution::execute(ex10, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 5);
BOOST_ASIO_CHECK(never_blocking_count == 5);
executor_type ex11 = boost::asio::prefer(ex7, execution::blocking.possibly);
execution::execute(ex11, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 6);
BOOST_ASIO_CHECK(never_blocking_count == 5);
executor_type ex12 = boost::asio::prefer(ex7, execution::blocking.never);
execution::execute(ex12, &do_nothing);
BOOST_ASIO_CHECK(possibly_blocking_count == 6);
BOOST_ASIO_CHECK(never_blocking_count == 6);
}
BOOST_ASIO_TEST_SUITE
(
"prefer_only",
BOOST_ASIO_TEST_CASE(prefer_only_executor_query_test)
BOOST_ASIO_TEST_CASE(prefer_only_executor_execute_test)
)

View File

@@ -0,0 +1,557 @@
//
// receiver.cpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/receiver.hpp>
#include <string>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
struct not_a_receiver
{
};
struct receiver
{
receiver()
{
}
receiver(const receiver&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver(receiver&&)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct receiver_of_0
{
receiver_of_0()
{
}
receiver_of_0(const receiver_of_0&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver_of_0(receiver_of_0&&)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
void set_value()
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver_of_0, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver_of_0>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_value_member<receiver_of_0, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct receiver_of_1
{
receiver_of_1()
{
}
receiver_of_1(const receiver_of_1&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver_of_1(receiver_of_1&&)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
void set_value(int) BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver_of_1, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver_of_1>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_value_member<receiver_of_1, void(int)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct receiver_of_2
{
receiver_of_2()
{
}
receiver_of_2(const receiver_of_2&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver_of_2(receiver_of_2&&)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
void set_value(int, std::string)
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver_of_2, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver_of_2>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_value_member<receiver_of_2, void(int, std::string)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void is_receiver_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver<
void,
boost::system::error_code
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver<
not_a_receiver,
boost::system::error_code
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver<
receiver,
boost::system::error_code
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver<
receiver_of_0,
boost::system::error_code
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver<
receiver_of_1,
boost::system::error_code
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver<
receiver_of_2,
boost::system::error_code
>::value));
}
void is_receiver_of_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
void
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
void,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
not_a_receiver
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
not_a_receiver,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
not_a_receiver,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver_of<
receiver_of_0
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_0,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_0,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_1
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver_of<
receiver_of_1,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_1,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_2
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_receiver_of<
receiver_of_2,
int
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_receiver_of<
receiver_of_2,
int,
std::string
>::value));
}
void is_nothrow_receiver_of_test()
{
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
void
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
void,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
not_a_receiver
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
not_a_receiver,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
not_a_receiver,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_0
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_0,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_0,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_1
>::value));
BOOST_ASIO_CHECK((
boost::asio::execution::is_nothrow_receiver_of<
receiver_of_1,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_1,
int,
std::string
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_2
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_2,
int
>::value));
BOOST_ASIO_CHECK((
!boost::asio::execution::is_nothrow_receiver_of<
receiver_of_2,
int,
std::string
>::value));
}
BOOST_ASIO_TEST_SUITE
(
"receiver",
BOOST_ASIO_TEST_CASE(is_receiver_test)
BOOST_ASIO_TEST_CASE(is_receiver_of_test)
BOOST_ASIO_TEST_CASE(is_nothrow_receiver_of_test)
)

View File

@@ -0,0 +1,506 @@
//
// schedule.cpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/schedule.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/execution/sender.hpp>
#include <boost/asio/execution/submit.hpp>
#include <boost/asio/traits/connect_member.hpp>
#include <boost/asio/traits/start_member.hpp>
#include <boost/asio/traits/submit_member.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct sender : exec::sender_base
{
sender()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
return operation_state();
}
template <typename R>
void submit(BOOST_ASIO_MOVE_ARG(R) r) const
{
typename boost::asio::decay<R>::type tmp(BOOST_ASIO_MOVE_CAST(R)(r));
exec::set_value(tmp);
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<const sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
template <typename R>
struct submit_member<const sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct no_schedule
{
};
struct const_member_schedule
{
sender schedule() const BOOST_ASIO_NOEXCEPT
{
return sender();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct schedule_member<const const_member_schedule>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef sender result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_MEMBER_TRAIT)
struct free_schedule_const_receiver
{
friend sender schedule(
const free_schedule_const_receiver&) BOOST_ASIO_NOEXCEPT
{
return sender();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct schedule_free<const free_schedule_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef sender result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_FREE_TRAIT)
struct non_const_member_schedule
{
sender schedule() BOOST_ASIO_NOEXCEPT
{
return sender();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct schedule_member<non_const_member_schedule>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef sender result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_MEMBER_TRAIT)
struct free_schedule_non_const_receiver
{
friend sender schedule(
free_schedule_non_const_receiver&) BOOST_ASIO_NOEXCEPT
{
return sender();
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct schedule_free<free_schedule_non_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef sender result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SCHEDULE_FREE_TRAIT)
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<F>::type tmp(BOOST_ASIO_MOVE_CAST(F)(f));
tmp();
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_can_schedule()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_schedule<
no_schedule&>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_schedule<
const no_schedule&>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_schedule<
const_member_schedule&>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_schedule<
const const_member_schedule&>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_schedule<
free_schedule_const_receiver&>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_schedule<
const free_schedule_const_receiver&>::value;
BOOST_ASIO_CHECK(b6 == true);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_schedule<
non_const_member_schedule&>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_schedule<
const non_const_member_schedule&>::value;
BOOST_ASIO_CHECK(b8 == false);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_schedule<
free_schedule_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_schedule<
const free_schedule_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b10 == false);
BOOST_ASIO_CONSTEXPR bool b11 = exec::can_schedule<
executor&>::value;
BOOST_ASIO_CHECK(b11 == true);
BOOST_ASIO_CONSTEXPR bool b12 = exec::can_schedule<
const executor&>::value;
BOOST_ASIO_CHECK(b12 == true);
}
struct receiver
{
int* count_;
receiver(int* count)
: count_(count)
{
}
receiver(const receiver& other) BOOST_ASIO_NOEXCEPT
: count_(other.count_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver(receiver&& other) BOOST_ASIO_NOEXCEPT
: count_(other.count_)
{
other.count_ = 0;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void set_value() BOOST_ASIO_NOEXCEPT
{
++(*count_);
}
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
template <>
struct set_value_member<receiver, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_schedule()
{
int count = 0;
const_member_schedule ex1 = {};
exec::submit(
exec::schedule(ex1),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const const_member_schedule ex2 = {};
exec::submit(
exec::schedule(ex2),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
exec::submit(
exec::schedule(const_member_schedule()),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
free_schedule_const_receiver ex3 = {};
exec::submit(
exec::schedule(ex3),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const free_schedule_const_receiver ex4 = {};
exec::submit(
exec::schedule(ex4),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
exec::submit(
exec::schedule(free_schedule_const_receiver()),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
non_const_member_schedule ex5 = {};
exec::submit(
exec::schedule(ex5),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
free_schedule_non_const_receiver ex6 = {};
exec::submit(
exec::schedule(ex6),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
executor ex7;
exec::submit(
exec::schedule(ex7),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
const executor ex8;
exec::submit(
exec::schedule(ex8),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
count = 0;
exec::submit(
exec::schedule(executor()),
receiver(&count));
BOOST_ASIO_CHECK(count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"schedule",
BOOST_ASIO_TEST_CASE(test_can_schedule)
BOOST_ASIO_TEST_CASE(test_schedule)
)

View File

@@ -0,0 +1,101 @@
//
// scheduler.cpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/scheduler.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
struct not_a_scheduler
{
};
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
(void)f;
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_is_scheduler()
{
BOOST_ASIO_CHECK(!exec::is_scheduler<void>::value);
BOOST_ASIO_CHECK(!exec::is_scheduler<not_a_scheduler>::value);
BOOST_ASIO_CHECK(exec::is_scheduler<executor>::value);
}
BOOST_ASIO_TEST_SUITE
(
"scheduler",
BOOST_ASIO_TEST_CASE(test_is_scheduler)
)

View File

@@ -0,0 +1,237 @@
//
// sender.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/sender.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
struct not_a_sender
{
};
struct sender_using_base :
boost::asio::execution::sender_base
{
sender_using_base()
{
}
};
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
(void)f;
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct typed_sender
{
template <
template <typename...> class Tuple,
template <typename...> class Variant>
using value_types = Variant<Tuple<int>>;
template <template <typename...> class Variant>
using error_types = Variant<boost::system::error_code>;
BOOST_ASIO_STATIC_CONSTEXPR(bool, sends_done = true);
typed_sender()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
return operation_state();
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<const typed_sender, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
template <typename T>
bool is_unspecialised(T*, ...)
{
return false;
}
template <typename T>
bool is_unspecialised(T*,
typename boost::asio::void_type<
typename exec::sender_traits<
T>::asio_execution_sender_traits_base_is_unspecialised
>::type*)
{
return true;
}
void test_sender_traits()
{
not_a_sender s1;
BOOST_ASIO_CHECK(is_unspecialised(&s1, static_cast<void*>(0)));
sender_using_base s2;
BOOST_ASIO_CHECK(!is_unspecialised(&s2, static_cast<void*>(0)));
executor s3;
BOOST_ASIO_CHECK(!is_unspecialised(&s3, static_cast<void*>(0)));
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
typed_sender s4;
BOOST_ASIO_CHECK(!is_unspecialised(&s4, static_cast<void*>(0)));
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
}
void test_is_sender()
{
BOOST_ASIO_CHECK(!exec::is_sender<void>::value);
BOOST_ASIO_CHECK(!exec::is_sender<not_a_sender>::value);
BOOST_ASIO_CHECK(exec::is_sender<sender_using_base>::value);
BOOST_ASIO_CHECK(exec::is_sender<executor>::value);
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
BOOST_ASIO_CHECK(exec::is_sender<typed_sender>::value);
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
}
void test_is_typed_sender()
{
BOOST_ASIO_CHECK(!exec::is_typed_sender<void>::value);
BOOST_ASIO_CHECK(!exec::is_typed_sender<not_a_sender>::value);
BOOST_ASIO_CHECK(!exec::is_typed_sender<sender_using_base>::value);
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
BOOST_ASIO_CHECK(exec::is_typed_sender<executor>::value);
BOOST_ASIO_CHECK(exec::is_typed_sender<typed_sender>::value);
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_TYPED_SENDER_TRAIT)
}
BOOST_ASIO_TEST_SUITE
(
"sender",
BOOST_ASIO_TEST_CASE(test_sender_traits)
BOOST_ASIO_TEST_CASE(test_is_sender)
BOOST_ASIO_TEST_CASE(test_is_typed_sender)
)

View File

@@ -0,0 +1,236 @@
//
// set_done.cpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/set_done.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct no_set_done
{
};
struct const_member_set_done
{
void set_done() const BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_done_member<const const_member_set_done>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
struct free_set_done_const_receiver
{
friend void set_done(const free_set_done_const_receiver&) BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_done_free<const free_set_done_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
struct non_const_member_set_done
{
void set_done() BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_done_member<non_const_member_set_done>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
struct free_set_done_non_const_receiver
{
friend void set_done(free_set_done_non_const_receiver&) BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_done_free<free_set_done_non_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
void test_can_set_done()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_set_done<
no_set_done&>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_set_done<
const no_set_done&>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_set_done<
const_member_set_done&>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_set_done<
const const_member_set_done&>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_set_done<
free_set_done_const_receiver&>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_set_done<
const free_set_done_const_receiver&>::value;
BOOST_ASIO_CHECK(b6 == true);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_set_done<
non_const_member_set_done&>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_set_done<
const non_const_member_set_done&>::value;
BOOST_ASIO_CHECK(b8 == false);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_set_done<
free_set_done_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_set_done<
const free_set_done_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b10 == false);
}
void increment(int* count)
{
++(*count);
}
void test_set_done()
{
call_count = 0;
const_member_set_done ex1 = {};
exec::set_done(ex1);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_set_done ex2 = {};
exec::set_done(ex2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_done(const_member_set_done());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_done_const_receiver ex3 = {};
exec::set_done(ex3);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_set_done_const_receiver ex4 = {};
exec::set_done(ex4);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_done(free_set_done_const_receiver());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_set_done ex5 = {};
exec::set_done(ex5);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_done_non_const_receiver ex6 = {};
exec::set_done(ex6);
BOOST_ASIO_CHECK(call_count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"set_done",
BOOST_ASIO_TEST_CASE(test_can_set_done)
BOOST_ASIO_TEST_CASE(test_set_done)
)

View File

@@ -0,0 +1,252 @@
//
// set_error.cpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/set_error.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct no_set_error
{
};
struct const_member_set_error
{
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) const BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<E>::type tmp(BOOST_ASIO_MOVE_CAST(E)(e));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename E>
struct set_error_member<const const_member_set_error, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
struct free_set_error_const_receiver
{
template <typename E>
friend void set_error(const free_set_error_const_receiver&,
BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<E>::type tmp(BOOST_ASIO_MOVE_CAST(E)(e));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename E>
struct set_error_free<const free_set_error_const_receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT)
struct non_const_member_set_error
{
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<E>::type tmp(BOOST_ASIO_MOVE_CAST(E)(e));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename E>
struct set_error_member<non_const_member_set_error, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
struct free_set_error_non_const_receiver
{
template <typename E>
friend void set_error(free_set_error_non_const_receiver&,
BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
typename boost::asio::decay<E>::type tmp(BOOST_ASIO_MOVE_CAST(E)(e));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename E>
struct set_error_free<free_set_error_non_const_receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT)
void test_can_set_error()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_set_error<
no_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_set_error<
const no_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_set_error<
const_member_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_set_error<
const const_member_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_set_error<
free_set_error_const_receiver&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_set_error<
const free_set_error_const_receiver&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b6 == true);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_set_error<
non_const_member_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_set_error<
const non_const_member_set_error&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b8 == false);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_set_error<
free_set_error_non_const_receiver&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_set_error<
const free_set_error_non_const_receiver&, boost::system::error_code>::value;
BOOST_ASIO_CHECK(b10 == false);
}
void increment(int* count)
{
++(*count);
}
void test_set_error()
{
boost::system::error_code ec;
call_count = 0;
const_member_set_error ex1 = {};
exec::set_error(ex1, ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_set_error ex2 = {};
exec::set_error(ex2, ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_error(const_member_set_error(), ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_error_const_receiver ex3 = {};
exec::set_error(ex3, ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_set_error_const_receiver ex4 = {};
exec::set_error(ex4, ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_error(free_set_error_const_receiver(), ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_set_error ex5 = {};
exec::set_error(ex5, ec);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_error_non_const_receiver ex6 = {};
exec::set_error(ex6, ec);
BOOST_ASIO_CHECK(call_count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"set_error",
BOOST_ASIO_TEST_CASE(test_can_set_error)
BOOST_ASIO_TEST_CASE(test_set_error)
)

View File

@@ -0,0 +1,844 @@
//
// set_value.cpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/set_value.hpp>
#include <string>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct no_set_value
{
};
struct const_member_set_value_0
{
void set_value() const
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_value_member<const const_member_set_value_0, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct const_member_set_value_1
{
template <typename V1>
void set_value(BOOST_ASIO_MOVE_ARG(V1) v1) const
{
typename boost::asio::decay<V1>::type tmp(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1>
struct set_value_member<const const_member_set_value_1, void(V1)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct const_member_set_value_2
{
template <typename V1, typename V2>
void set_value(BOOST_ASIO_MOVE_ARG(V1) v1, BOOST_ASIO_MOVE_ARG(V2) v2) const
{
typename boost::asio::decay<V1>::type tmp1(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp1;
typename boost::asio::decay<V2>::type tmp2(BOOST_ASIO_MOVE_CAST(V2)(v2));
(void)tmp2;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1, typename V2>
struct set_value_member<const const_member_set_value_2, void(V1, V2)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct free_set_value_const_receiver_0
{
friend void set_value(const free_set_value_const_receiver_0&)
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_value_free<const free_set_value_const_receiver_0, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
struct free_set_value_const_receiver_1
{
template <typename V1>
friend void set_value(const free_set_value_const_receiver_1&,
BOOST_ASIO_MOVE_ARG(V1) v1)
{
typename boost::asio::decay<V1>::type tmp(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1>
struct set_value_free<const free_set_value_const_receiver_1, void(V1)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
struct free_set_value_const_receiver_2
{
template <typename V1, typename V2>
friend void set_value(const free_set_value_const_receiver_2&,
BOOST_ASIO_MOVE_ARG(V1) v1, BOOST_ASIO_MOVE_ARG(V2) v2)
{
typename boost::asio::decay<V1>::type tmp1(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp1;
typename boost::asio::decay<V2>::type tmp2(BOOST_ASIO_MOVE_CAST(V2)(v2));
(void)tmp2;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1, typename V2>
struct set_value_free<const free_set_value_const_receiver_2, void(V1, V2)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
struct non_const_member_set_value_0
{
void set_value()
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_value_member<non_const_member_set_value_0, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct non_const_member_set_value_1
{
template <typename V1>
void set_value(BOOST_ASIO_MOVE_ARG(V1) v1)
{
typename boost::asio::decay<V1>::type tmp(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1>
struct set_value_member<non_const_member_set_value_1, void(V1)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct non_const_member_set_value_2
{
template <typename V1, typename V2>
void set_value(BOOST_ASIO_MOVE_ARG(V1) v1, BOOST_ASIO_MOVE_ARG(V2) v2)
{
typename boost::asio::decay<V1>::type tmp1(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp1;
typename boost::asio::decay<V2>::type tmp2(BOOST_ASIO_MOVE_CAST(V2)(v2));
(void)tmp2;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1, typename V2>
struct set_value_member<non_const_member_set_value_2, void(V1, V2)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
struct free_set_value_non_const_receiver_0
{
friend void set_value(free_set_value_non_const_receiver_0&)
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct set_value_free<free_set_value_non_const_receiver_0, void()>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
struct free_set_value_non_const_receiver_1
{
template <typename V1>
friend void set_value(free_set_value_non_const_receiver_1&,
BOOST_ASIO_MOVE_ARG(V1) v1)
{
typename boost::asio::decay<V1>::type tmp(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1>
struct set_value_free<free_set_value_non_const_receiver_1, void(V1)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
struct free_set_value_non_const_receiver_2
{
template <typename V1, typename V2>
friend void set_value(free_set_value_non_const_receiver_2&,
BOOST_ASIO_MOVE_ARG(V1) v1, BOOST_ASIO_MOVE_ARG(V2) v2)
{
typename boost::asio::decay<V1>::type tmp1(BOOST_ASIO_MOVE_CAST(V1)(v1));
(void)tmp1;
typename boost::asio::decay<V2>::type tmp2(BOOST_ASIO_MOVE_CAST(V2)(v2));
(void)tmp2;
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename V1, typename V2>
struct set_value_free<free_set_value_non_const_receiver_2, void(V1, V2)>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
void test_can_set_value()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_set_value<
no_set_value&>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_set_value<
const no_set_value&>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_set_value<
no_set_value&, int>::value;
BOOST_ASIO_CHECK(b3 == false);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_set_value<
const no_set_value&, int>::value;
BOOST_ASIO_CHECK(b4 == false);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_set_value<
no_set_value&, int, std::string>::value;
BOOST_ASIO_CHECK(b5 == false);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_set_value<
const no_set_value&, int, std::string>::value;
BOOST_ASIO_CHECK(b6 == false);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_set_value<
const_member_set_value_0&>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_set_value<
const const_member_set_value_0&>::value;
BOOST_ASIO_CHECK(b8 == true);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_set_value<
const_member_set_value_0&, int>::value;
BOOST_ASIO_CHECK(b9 == false);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_set_value<
const const_member_set_value_0&, int>::value;
BOOST_ASIO_CHECK(b10 == false);
BOOST_ASIO_CONSTEXPR bool b11 = exec::can_set_value<
const_member_set_value_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b11 == false);
BOOST_ASIO_CONSTEXPR bool b12 = exec::can_set_value<
const const_member_set_value_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b12 == false);
BOOST_ASIO_CONSTEXPR bool b13 = exec::can_set_value<
const_member_set_value_1&>::value;
BOOST_ASIO_CHECK(b13 == false);
BOOST_ASIO_CONSTEXPR bool b14 = exec::can_set_value<
const const_member_set_value_1&>::value;
BOOST_ASIO_CHECK(b14 == false);
BOOST_ASIO_CONSTEXPR bool b15 = exec::can_set_value<
const_member_set_value_1&, int>::value;
BOOST_ASIO_CHECK(b15 == true);
BOOST_ASIO_CONSTEXPR bool b16 = exec::can_set_value<
const const_member_set_value_1&, int>::value;
BOOST_ASIO_CHECK(b16 == true);
BOOST_ASIO_CONSTEXPR bool b17 = exec::can_set_value<
const_member_set_value_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b17 == false);
BOOST_ASIO_CONSTEXPR bool b18 = exec::can_set_value<
const const_member_set_value_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b18 == false);
BOOST_ASIO_CONSTEXPR bool b19 = exec::can_set_value<
const_member_set_value_2&>::value;
BOOST_ASIO_CHECK(b19 == false);
BOOST_ASIO_CONSTEXPR bool b20 = exec::can_set_value<
const const_member_set_value_2&>::value;
BOOST_ASIO_CHECK(b20 == false);
BOOST_ASIO_CONSTEXPR bool b21 = exec::can_set_value<
const_member_set_value_2&, int>::value;
BOOST_ASIO_CHECK(b21 == false);
BOOST_ASIO_CONSTEXPR bool b22 = exec::can_set_value<
const const_member_set_value_2&, int>::value;
BOOST_ASIO_CHECK(b22 == false);
BOOST_ASIO_CONSTEXPR bool b23 = exec::can_set_value<
const_member_set_value_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b23 == true);
BOOST_ASIO_CONSTEXPR bool b24 = exec::can_set_value<
const const_member_set_value_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b24 == true);
BOOST_ASIO_CONSTEXPR bool b25 = exec::can_set_value<
free_set_value_const_receiver_0&>::value;
BOOST_ASIO_CHECK(b25 == true);
BOOST_ASIO_CONSTEXPR bool b26 = exec::can_set_value<
const free_set_value_const_receiver_0&>::value;
BOOST_ASIO_CHECK(b26 == true);
BOOST_ASIO_CONSTEXPR bool b27 = exec::can_set_value<
free_set_value_const_receiver_0&, int>::value;
BOOST_ASIO_CHECK(b27 == false);
BOOST_ASIO_CONSTEXPR bool b28 = exec::can_set_value<
const free_set_value_const_receiver_0&, int>::value;
BOOST_ASIO_CHECK(b28 == false);
BOOST_ASIO_CONSTEXPR bool b29 = exec::can_set_value<
free_set_value_const_receiver_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b29 == false);
BOOST_ASIO_CONSTEXPR bool b30 = exec::can_set_value<
const free_set_value_const_receiver_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b30 == false);
BOOST_ASIO_CONSTEXPR bool b31 = exec::can_set_value<
free_set_value_const_receiver_1&>::value;
BOOST_ASIO_CHECK(b31 == false);
BOOST_ASIO_CONSTEXPR bool b32 = exec::can_set_value<
const free_set_value_const_receiver_1&>::value;
BOOST_ASIO_CHECK(b32 == false);
BOOST_ASIO_CONSTEXPR bool b33 = exec::can_set_value<
free_set_value_const_receiver_1&, int>::value;
BOOST_ASIO_CHECK(b33 == true);
BOOST_ASIO_CONSTEXPR bool b34 = exec::can_set_value<
const free_set_value_const_receiver_1&, int>::value;
BOOST_ASIO_CHECK(b34 == true);
BOOST_ASIO_CONSTEXPR bool b35 = exec::can_set_value<
free_set_value_const_receiver_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b35 == false);
BOOST_ASIO_CONSTEXPR bool b36 = exec::can_set_value<
const free_set_value_const_receiver_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b36 == false);
BOOST_ASIO_CONSTEXPR bool b37 = exec::can_set_value<
free_set_value_const_receiver_2&>::value;
BOOST_ASIO_CHECK(b37 == false);
BOOST_ASIO_CONSTEXPR bool b38 = exec::can_set_value<
const free_set_value_const_receiver_2&>::value;
BOOST_ASIO_CHECK(b38 == false);
BOOST_ASIO_CONSTEXPR bool b39 = exec::can_set_value<
free_set_value_const_receiver_2&, int>::value;
BOOST_ASIO_CHECK(b39 == false);
BOOST_ASIO_CONSTEXPR bool b40 = exec::can_set_value<
const free_set_value_const_receiver_2&, int>::value;
BOOST_ASIO_CHECK(b40 == false);
BOOST_ASIO_CONSTEXPR bool b41 = exec::can_set_value<
free_set_value_const_receiver_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b41 == true);
BOOST_ASIO_CONSTEXPR bool b42 = exec::can_set_value<
const free_set_value_const_receiver_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b42 == true);
BOOST_ASIO_CONSTEXPR bool b43 = exec::can_set_value<
non_const_member_set_value_0&>::value;
BOOST_ASIO_CHECK(b43 == true);
BOOST_ASIO_CONSTEXPR bool b44 = exec::can_set_value<
const non_const_member_set_value_0&>::value;
BOOST_ASIO_CHECK(b44 == false);
BOOST_ASIO_CONSTEXPR bool b45 = exec::can_set_value<
non_const_member_set_value_0&, int>::value;
BOOST_ASIO_CHECK(b45 == false);
BOOST_ASIO_CONSTEXPR bool b46 = exec::can_set_value<
const non_const_member_set_value_0&, int>::value;
BOOST_ASIO_CHECK(b46 == false);
BOOST_ASIO_CONSTEXPR bool b47 = exec::can_set_value<
non_const_member_set_value_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b47 == false);
BOOST_ASIO_CONSTEXPR bool b48 = exec::can_set_value<
const non_const_member_set_value_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b48 == false);
BOOST_ASIO_CONSTEXPR bool b49 = exec::can_set_value<
non_const_member_set_value_1&>::value;
BOOST_ASIO_CHECK(b49 == false);
BOOST_ASIO_CONSTEXPR bool b50 = exec::can_set_value<
const non_const_member_set_value_1&>::value;
BOOST_ASIO_CHECK(b50 == false);
BOOST_ASIO_CONSTEXPR bool b51 = exec::can_set_value<
non_const_member_set_value_1&, int>::value;
BOOST_ASIO_CHECK(b51 == true);
BOOST_ASIO_CONSTEXPR bool b52 = exec::can_set_value<
const non_const_member_set_value_1&, int>::value;
BOOST_ASIO_CHECK(b52 == false);
BOOST_ASIO_CONSTEXPR bool b53 = exec::can_set_value<
non_const_member_set_value_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b53 == false);
BOOST_ASIO_CONSTEXPR bool b54 = exec::can_set_value<
const non_const_member_set_value_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b54 == false);
BOOST_ASIO_CONSTEXPR bool b55 = exec::can_set_value<
non_const_member_set_value_2&>::value;
BOOST_ASIO_CHECK(b55 == false);
BOOST_ASIO_CONSTEXPR bool b56 = exec::can_set_value<
const non_const_member_set_value_2&>::value;
BOOST_ASIO_CHECK(b56 == false);
BOOST_ASIO_CONSTEXPR bool b57 = exec::can_set_value<
non_const_member_set_value_2&, int>::value;
BOOST_ASIO_CHECK(b57 == false);
BOOST_ASIO_CONSTEXPR bool b58 = exec::can_set_value<
const non_const_member_set_value_2&, int>::value;
BOOST_ASIO_CHECK(b58 == false);
BOOST_ASIO_CONSTEXPR bool b59 = exec::can_set_value<
non_const_member_set_value_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b59 == true);
BOOST_ASIO_CONSTEXPR bool b60 = exec::can_set_value<
const non_const_member_set_value_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b60 == false);
BOOST_ASIO_CONSTEXPR bool b61 = exec::can_set_value<
free_set_value_non_const_receiver_0&>::value;
BOOST_ASIO_CHECK(b61 == true);
BOOST_ASIO_CONSTEXPR bool b62 = exec::can_set_value<
const free_set_value_non_const_receiver_0&>::value;
BOOST_ASIO_CHECK(b62 == false);
BOOST_ASIO_CONSTEXPR bool b63 = exec::can_set_value<
free_set_value_non_const_receiver_0&, int>::value;
BOOST_ASIO_CHECK(b63 == false);
BOOST_ASIO_CONSTEXPR bool b64 = exec::can_set_value<
const free_set_value_non_const_receiver_0&, int>::value;
BOOST_ASIO_CHECK(b64 == false);
BOOST_ASIO_CONSTEXPR bool b65 = exec::can_set_value<
free_set_value_non_const_receiver_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b65 == false);
BOOST_ASIO_CONSTEXPR bool b66 = exec::can_set_value<
const free_set_value_non_const_receiver_0&, int, std::string>::value;
BOOST_ASIO_CHECK(b66 == false);
BOOST_ASIO_CONSTEXPR bool b67 = exec::can_set_value<
free_set_value_non_const_receiver_1&>::value;
BOOST_ASIO_CHECK(b67 == false);
BOOST_ASIO_CONSTEXPR bool b68 = exec::can_set_value<
const free_set_value_non_const_receiver_1&>::value;
BOOST_ASIO_CHECK(b68 == false);
BOOST_ASIO_CONSTEXPR bool b69 = exec::can_set_value<
free_set_value_non_const_receiver_1&, int>::value;
BOOST_ASIO_CHECK(b69 == true);
BOOST_ASIO_CONSTEXPR bool b70 = exec::can_set_value<
const free_set_value_non_const_receiver_1&, int>::value;
BOOST_ASIO_CHECK(b70 == false);
BOOST_ASIO_CONSTEXPR bool b71 = exec::can_set_value<
free_set_value_non_const_receiver_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b71 == false);
BOOST_ASIO_CONSTEXPR bool b72 = exec::can_set_value<
const free_set_value_non_const_receiver_1&, int, std::string>::value;
BOOST_ASIO_CHECK(b72 == false);
BOOST_ASIO_CONSTEXPR bool b73 = exec::can_set_value<
free_set_value_non_const_receiver_2&>::value;
BOOST_ASIO_CHECK(b73 == false);
BOOST_ASIO_CONSTEXPR bool b74 = exec::can_set_value<
const free_set_value_non_const_receiver_2&>::value;
BOOST_ASIO_CHECK(b74 == false);
BOOST_ASIO_CONSTEXPR bool b75 = exec::can_set_value<
free_set_value_non_const_receiver_2&, int>::value;
BOOST_ASIO_CHECK(b75 == false);
BOOST_ASIO_CONSTEXPR bool b76 = exec::can_set_value<
const free_set_value_non_const_receiver_2&, int>::value;
BOOST_ASIO_CHECK(b76 == false);
BOOST_ASIO_CONSTEXPR bool b77 = exec::can_set_value<
free_set_value_non_const_receiver_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b77 == true);
BOOST_ASIO_CONSTEXPR bool b78 = exec::can_set_value<
const free_set_value_non_const_receiver_2&, int, std::string>::value;
BOOST_ASIO_CHECK(b78 == false);
}
void increment(int* count)
{
++(*count);
}
void test_set_value()
{
call_count = 0;
const_member_set_value_0 ex1 = {};
exec::set_value(ex1);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_set_value_0 ex2 = {};
exec::set_value(ex2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(const_member_set_value_0());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const_member_set_value_1 ex3 = {};
exec::set_value(ex3, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_set_value_1 ex4 = {};
exec::set_value(ex4, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(const_member_set_value_1(), 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const_member_set_value_2 ex5 = {};
exec::set_value(ex5, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_set_value_2 ex6 = {};
exec::set_value(ex6, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(const_member_set_value_2(), 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_const_receiver_0 ex7 = {};
exec::set_value(ex7);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_set_value_const_receiver_0 ex8 = {};
exec::set_value(ex8);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(free_set_value_const_receiver_0());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_const_receiver_1 ex9 = {};
exec::set_value(ex9, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_set_value_const_receiver_1 ex10 = {};
exec::set_value(ex10, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(free_set_value_const_receiver_1(), 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_const_receiver_2 ex11 = {};
exec::set_value(ex11, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_set_value_const_receiver_2 ex12 = {};
exec::set_value(ex12, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::set_value(free_set_value_const_receiver_2(), 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_set_value_0 ex13 = {};
exec::set_value(ex13);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_set_value_1 ex14 = {};
exec::set_value(ex14, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_set_value_2 ex15 = {};
exec::set_value(ex15, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_non_const_receiver_0 ex16 = {};
exec::set_value(ex16);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_non_const_receiver_1 ex17 = {};
exec::set_value(ex17, 123);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_set_value_non_const_receiver_2 ex18 = {};
exec::set_value(ex18, 123, std::string());
BOOST_ASIO_CHECK(call_count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"set_value",
BOOST_ASIO_TEST_CASE(test_can_set_value)
BOOST_ASIO_TEST_CASE(test_set_value)
)

View File

@@ -0,0 +1,236 @@
//
// start.cpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/start.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct no_start
{
};
struct const_member_start
{
void start() const BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct start_member<const const_member_start>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
struct free_start_const_receiver
{
friend void start(const free_start_const_receiver&) BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct start_free<const free_start_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
struct non_const_member_start
{
void start() BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct start_member<non_const_member_start>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
struct free_start_non_const_receiver
{
friend void start(free_start_non_const_receiver&) BOOST_ASIO_NOEXCEPT
{
++call_count;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <>
struct start_free<free_start_non_const_receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
void test_can_start()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_start<
no_start&>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_start<
const no_start&>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_start<
const_member_start&>::value;
BOOST_ASIO_CHECK(b3 == true);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_start<
const const_member_start&>::value;
BOOST_ASIO_CHECK(b4 == true);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_start<
free_start_const_receiver&>::value;
BOOST_ASIO_CHECK(b5 == true);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_start<
const free_start_const_receiver&>::value;
BOOST_ASIO_CHECK(b6 == true);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_start<
non_const_member_start&>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_start<
const non_const_member_start&>::value;
BOOST_ASIO_CHECK(b8 == false);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_start<
free_start_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_start<
const free_start_non_const_receiver&>::value;
BOOST_ASIO_CHECK(b10 == false);
}
void increment(int* count)
{
++(*count);
}
void test_start()
{
call_count = 0;
const_member_start ex1 = {};
exec::start(ex1);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_start ex2 = {};
exec::start(ex2);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::start(const_member_start());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_start_const_receiver ex3 = {};
exec::start(ex3);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_start_const_receiver ex4 = {};
exec::start(ex4);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::start(free_start_const_receiver());
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_start ex5 = {};
exec::start(ex5);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_start_non_const_receiver ex6 = {};
exec::start(ex6);
BOOST_ASIO_CHECK(call_count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"start",
BOOST_ASIO_TEST_CASE(test_can_start)
BOOST_ASIO_TEST_CASE(test_start)
)

View File

@@ -0,0 +1,562 @@
//
// submit.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/execution/submit.hpp>
#include <boost/system/error_code.hpp>
#include "../unit_test.hpp"
namespace exec = boost::asio::execution;
static int call_count = 0;
struct operation_state
{
void start() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct no_submit_1
{
};
struct no_submit_2 : exec::sender_base
{
};
struct no_submit_3
{
template <typename R>
void submit(BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
}
};
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
namespace boost {
namespace asio {
namespace traits {
template <typename R>
struct submit_member<no_submit_3, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
} // namespace traits
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
struct const_member_submit : exec::sender_base
{
const_member_submit()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
return operation_state();
}
template <typename R>
void submit(BOOST_ASIO_MOVE_ARG(R) r) const
{
(void)r;
++call_count;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<const const_member_submit, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
template <typename R>
struct submit_member<const const_member_submit, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct free_submit_const_receiver : exec::sender_base
{
free_submit_const_receiver()
{
}
template <typename R>
friend operation_state connect(
const free_submit_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
return operation_state();
}
template <typename R>
friend void submit(
const free_submit_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
template <typename R>
struct connect_free<const free_submit_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
template <typename R>
struct submit_free<const free_submit_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct non_const_member_submit : exec::sender_base
{
non_const_member_submit()
{
}
template <typename R>
operation_state connect(BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
return operation_state();
}
template <typename R>
void submit(BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
template <typename R>
struct connect_member<non_const_member_submit, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
template <typename R>
struct submit_member<non_const_member_submit, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct free_submit_non_const_receiver : exec::sender_base
{
free_submit_non_const_receiver()
{
}
template <typename R>
friend operation_state connect(
free_submit_non_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
return operation_state();
}
template <typename R>
friend void submit(
free_submit_non_const_receiver&, BOOST_ASIO_MOVE_ARG(R) r)
{
(void)r;
++call_count;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
template <typename R>
struct connect_free<free_submit_non_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef operation_state result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_CONNECT_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
template <typename R>
struct submit_free<free_submit_non_const_receiver, R>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_FREE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct receiver
{
receiver()
{
}
receiver(const receiver&)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
receiver(receiver&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename E>
void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT
{
(void)e;
}
void set_done() BOOST_ASIO_NOEXCEPT
{
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
template <typename E>
struct set_error_member<receiver, E>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
template <>
struct set_done_member<receiver>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
struct executor
{
executor()
{
}
executor(const executor&) BOOST_ASIO_NOEXCEPT
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
executor(executor&&) BOOST_ASIO_NOEXCEPT
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename F>
void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
{
(void)f;
++call_count;
}
bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
{
return true;
}
bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
{
return false;
}
};
namespace boost {
namespace asio {
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F>
struct execute_member<executor, F>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <>
struct equality_comparable<executor>
{
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
} // namespace traits
} // namespace asio
} // namespace boost
void test_can_submit()
{
BOOST_ASIO_CONSTEXPR bool b1 = exec::can_submit<
no_submit_1&, receiver>::value;
BOOST_ASIO_CHECK(b1 == false);
BOOST_ASIO_CONSTEXPR bool b2 = exec::can_submit<
const no_submit_1&, receiver>::value;
BOOST_ASIO_CHECK(b2 == false);
BOOST_ASIO_CONSTEXPR bool b3 = exec::can_submit<
no_submit_2&, receiver>::value;
BOOST_ASIO_CHECK(b3 == false);
BOOST_ASIO_CONSTEXPR bool b4 = exec::can_submit<
const no_submit_2&, receiver>::value;
BOOST_ASIO_CHECK(b4 == false);
BOOST_ASIO_CONSTEXPR bool b5 = exec::can_submit<
no_submit_3&, receiver>::value;
BOOST_ASIO_CHECK(b5 == false);
BOOST_ASIO_CONSTEXPR bool b6 = exec::can_submit<
const no_submit_3&, receiver>::value;
BOOST_ASIO_CHECK(b6 == false);
BOOST_ASIO_CONSTEXPR bool b7 = exec::can_submit<
const_member_submit&, receiver>::value;
BOOST_ASIO_CHECK(b7 == true);
BOOST_ASIO_CONSTEXPR bool b8 = exec::can_submit<
const const_member_submit&, receiver>::value;
BOOST_ASIO_CHECK(b8 == true);
BOOST_ASIO_CONSTEXPR bool b9 = exec::can_submit<
free_submit_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b9 == true);
BOOST_ASIO_CONSTEXPR bool b10 = exec::can_submit<
const free_submit_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b10 == true);
BOOST_ASIO_CONSTEXPR bool b11 = exec::can_submit<
non_const_member_submit&, receiver>::value;
BOOST_ASIO_CHECK(b11 == true);
BOOST_ASIO_CONSTEXPR bool b12 = exec::can_submit<
const non_const_member_submit&, receiver>::value;
BOOST_ASIO_CHECK(b12 == false);
BOOST_ASIO_CONSTEXPR bool b13 = exec::can_submit<
free_submit_non_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b13 == true);
BOOST_ASIO_CONSTEXPR bool b14 = exec::can_submit<
const free_submit_non_const_receiver&, receiver>::value;
BOOST_ASIO_CHECK(b14 == false);
BOOST_ASIO_CONSTEXPR bool b15 = exec::can_submit<
executor&, receiver>::value;
BOOST_ASIO_CHECK(b15 == true);
BOOST_ASIO_CONSTEXPR bool b16 = exec::can_submit<
const executor&, receiver>::value;
BOOST_ASIO_CHECK(b16 == true);
}
void increment(int* count)
{
++(*count);
}
void test_submit()
{
receiver r;
call_count = 0;
const_member_submit s1;
exec::submit(s1, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const const_member_submit s2;
exec::submit(s2, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::submit(const_member_submit(), r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_submit_const_receiver s3;
exec::submit(s3, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const free_submit_const_receiver s4;
exec::submit(s4, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::submit(free_submit_const_receiver(), r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
non_const_member_submit s5;
exec::submit(s5, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
free_submit_non_const_receiver s6;
exec::submit(s6, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
executor s7;
exec::submit(s7, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
const executor s8;
exec::submit(s8, r);
BOOST_ASIO_CHECK(call_count == 1);
call_count = 0;
exec::submit(executor(), r);
BOOST_ASIO_CHECK(call_count == 1);
}
BOOST_ASIO_TEST_SUITE
(
"submit",
BOOST_ASIO_TEST_CASE(test_can_submit)
BOOST_ASIO_TEST_CASE(test_submit)
)