Add execution::operation_state concept and execution::is_operation_state trait.

This commit is contained in:
Christopher Kohlhoff 2020-06-29 09:18:13 +10:00
parent 1a5fa59815
commit 4a5a7c5c0e
9 changed files with 192 additions and 0 deletions

View File

@ -308,6 +308,7 @@ nobase_include_HEADERS = \
asio/execution/invocable_archetype.hpp \
asio/execution/mapping.hpp \
asio/execution/occupancy.hpp \
asio/execution/operation_state.hpp \
asio/execution/outstanding_work.hpp \
asio/execution/prefer_only.hpp \
asio/execution/receiver.hpp \

View File

@ -66,6 +66,7 @@
#include "asio/execution/invocable_archetype.hpp"
#include "asio/execution/mapping.hpp"
#include "asio/execution/occupancy.hpp"
#include "asio/execution/operation_state.hpp"
#include "asio/execution/outstanding_work.hpp"
#include "asio/execution/prefer_only.hpp"
#include "asio/execution/receiver.hpp"

View File

@ -36,6 +36,7 @@
# include <boost/type_traits/is_copy_constructible.hpp>
# include <boost/type_traits/is_destructible.hpp>
# include <boost/type_traits/is_function.hpp>
# include <boost/type_traits/is_object.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/type_traits/remove_cv.hpp>
# include <boost/type_traits/remove_pointer.hpp>
@ -68,6 +69,7 @@ using std::is_function;
using std::is_move_constructible;
using std::is_nothrow_copy_constructible;
using std::is_nothrow_destructible;
using std::is_object;
using std::is_reference;
using std::is_same;
using std::is_scalar;
@ -114,6 +116,7 @@ template <typename T>
struct is_nothrow_copy_constructible : boost::has_nothrow_copy<T> {};
template <typename T>
struct is_nothrow_destructible : boost::has_nothrow_destructor<T> {};
using boost::is_object;
using boost::is_reference;
using boost::is_same;
using boost::is_scalar;

View File

@ -28,6 +28,7 @@
#include "asio/execution/invocable_archetype.hpp"
#include "asio/execution/mapping.hpp"
#include "asio/execution/occupancy.hpp"
#include "asio/execution/operation_state.hpp"
#include "asio/execution/outstanding_work.hpp"
#include "asio/execution/prefer_only.hpp"
#include "asio/execution/receiver.hpp"

View File

@ -0,0 +1,82 @@
//
// execution/operation_state.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
//
#ifndef ASIO_EXECUTION_OPERATION_STATE_HPP
#define ASIO_EXECUTION_OPERATION_STATE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/execution/start.hpp"
#if defined(ASIO_HAS_DEDUCED_START_FREE_TRAIT) \
&& defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
# define ASIO_HAS_DEDUCED_EXECUTION_IS_OPERATION_STATE_TRAIT 1
#endif // defined(ASIO_HAS_DEDUCED_START_FREE_TRAIT)
// && defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace execution {
/// The is_operation_state trait detects whether a type T satisfies the
/// execution::operation_state concept.
/**
* Class template @c is_operation_state is a type trait that is derived from
* @c true_type if the type @c T meets the concept definition for an
* @c operation_state, otherwise @c false_type.
*/
template <typename T>
struct is_operation_state :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
integral_constant<bool,
is_destructible<T>::value
&& is_object<T>::value
&& can_start<T&>::value
&& is_nothrow_start<T&>::value
>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
ASIO_CONSTEXPR const bool is_operation_state_v =
is_operation_state<T>::value;
#endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(ASIO_HAS_CONCEPTS)
template <typename T>
ASIO_CONCEPT operation_state = is_operation_state<T>::value;
#define ASIO_EXECUTION_OPERATION_STATE \
::asio::execution::operation_state
#else // defined(ASIO_HAS_CONCEPTS)
#define ASIO_EXECUTION_OPERATION_STATE typename
#endif // defined(ASIO_HAS_CONCEPTS)
} // namespace execution
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_EXECUTION_OPERATION_STATE_HPP

View File

@ -156,6 +156,7 @@ UNIT_TEST_EXES = \
tests\unit\execution\executor.exe \
tests\unit\execution\invocable_archetype.exe \
tests\unit\execution\mapping.exe \
tests\unit\execution\operation_state.exe \
tests\unit\execution\outstanding_work.exe \
tests\unit\execution\prefer_only.exe \
tests\unit\execution\receiver.exe \

View File

@ -52,6 +52,7 @@ check_PROGRAMS = \
unit/execution/executor \
unit/execution/invocable_archetype \
unit/execution/mapping \
unit/execution/operation_state \
unit/execution/outstanding_work \
unit/execution/prefer_only \
unit/execution/receiver \
@ -211,6 +212,7 @@ TESTS = \
unit/execution/executor \
unit/execution/invocable_archetype \
unit/execution/mapping \
unit/execution/operation_state \
unit/execution/outstanding_work \
unit/execution/prefer_only \
unit/execution/receiver \
@ -371,6 +373,7 @@ unit_execution_executor_SOURCES = unit/execution/executor.cpp
unit_execution_invocable_archetype_SOURCES = unit/execution/invocable_archetype.cpp
unit_execution_mapping_SOURCES = unit/execution/mapping.cpp
unit_execution_outstanding_work_SOURCES = unit/execution/outstanding_work.cpp
unit_execution_operation_state_SOURCES = unit/execution/operation_state.cpp
unit_execution_prefer_only_SOURCES = unit/execution/prefer_only.cpp
unit_execution_receiver_SOURCES = unit/execution/receiver.cpp
unit_execution_relationship_SOURCES = unit/execution/relationship.cpp

View File

@ -16,6 +16,7 @@ execute
executor
invocable_archetype
mapping
operation_state
outstanding_work
prefer_only
receiver

View File

@ -0,0 +1,99 @@
//
// operation_state.cpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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 "asio/execution/operation_state.hpp"
#include <string>
#include "asio/error_code.hpp"
#include "../unit_test.hpp"
struct not_an_operation_state_1
{
};
struct not_an_operation_state_2
{
void start()
{
}
};
namespace asio {
namespace traits {
#if !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<not_an_operation_state_2>
{
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
typedef void result_type;
};
#endif // !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
struct operation_state
{
void start() ASIO_NOEXCEPT
{
}
};
namespace asio {
namespace traits {
#if !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
template <>
struct start_member<operation_state>
{
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
typedef void result_type;
};
#endif // !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
} // namespace traits
} // namespace asio
void is_operation_state_test()
{
ASIO_CHECK((
!asio::execution::is_operation_state<
not_an_operation_state_1
>::value));
ASIO_CHECK((
!asio::execution::is_operation_state<
not_an_operation_state_2
>::value));
ASIO_CHECK((
asio::execution::is_operation_state<
operation_state
>::value));
}
ASIO_TEST_SUITE
(
"operation_state",
ASIO_TEST_CASE(is_operation_state_test)
)