mirror of
https://github.com/boostorg/asio.git
synced 2026-01-26 18:22:09 +00:00
Add execution::executor concept and execution::is_executor trait.
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/execution/execute.hpp>
|
||||
#include <boost/asio/execution/executor.hpp>
|
||||
#include <boost/asio/execution/invocable_archetype.hpp>
|
||||
#include <boost/asio/execution_context.hpp>
|
||||
#include <boost/asio/executor.hpp>
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/type_traits/conditional.hpp>
|
||||
# include <boost/type_traits/decay.hpp>
|
||||
# include <boost/type_traits/has_nothrow_copy.hpp>
|
||||
# include <boost/type_traits/has_nothrow_destructor.hpp>
|
||||
# include <boost/type_traits/integral_constant.hpp>
|
||||
# include <boost/type_traits/is_base_of.hpp>
|
||||
# include <boost/type_traits/is_class.hpp>
|
||||
# include <boost/type_traits/is_const.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# 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_same.hpp>
|
||||
# include <boost/type_traits/remove_pointer.hpp>
|
||||
@@ -52,7 +56,11 @@ using std::is_base_of;
|
||||
using std::is_class;
|
||||
using std::is_const;
|
||||
using std::is_convertible;
|
||||
using std::is_copy_constructible;
|
||||
using std::is_destructible;
|
||||
using std::is_function;
|
||||
using std::is_nothrow_copy_constructible;
|
||||
using std::is_nothrow_destructible;
|
||||
using std::is_same;
|
||||
using std::remove_pointer;
|
||||
using std::remove_reference;
|
||||
@@ -77,7 +85,13 @@ using boost::is_base_of;
|
||||
using boost::is_class;
|
||||
using boost::is_const;
|
||||
using boost::is_convertible;
|
||||
using boost::is_copy_constructible;
|
||||
using boost::is_destructible;
|
||||
using boost::is_function;
|
||||
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_same;
|
||||
using boost::remove_pointer;
|
||||
using boost::remove_reference;
|
||||
|
||||
92
include/boost/asio/execution/executor.hpp
Normal file
92
include/boost/asio/execution/executor.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// execution/executor.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 BOOST_ASIO_EXECUTION_EXECUTOR_HPP
|
||||
#define BOOST_ASIO_EXECUTION_EXECUTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <boost/asio/detail/type_traits.hpp>
|
||||
#include <boost/asio/execution/execute.hpp>
|
||||
#include <boost/asio/execution/invocable_archetype.hpp>
|
||||
#include <boost/asio/traits/equality_comparable.hpp>
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT) \
|
||||
&& defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
|
||||
&& defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
|
||||
# define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
|
||||
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
|
||||
// && defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
|
||||
// && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
namespace execution {
|
||||
|
||||
/// The is_executor trait detects whether a type T satisfies the
|
||||
/// execution::executor concept.
|
||||
/**
|
||||
* Class template @c is_executor is a UnaryTypeTrait that is derived from @c
|
||||
* true_type if the type @c T meets the concept definition for an executor,
|
||||
* otherwise @c false_type.
|
||||
*/
|
||||
template <typename T>
|
||||
struct is_executor :
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
integral_constant<bool, automatically_determined>
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
integral_constant<bool,
|
||||
can_execute<const T, invocable_archetype>::value
|
||||
#if defined(BOOST_ASIO_HAS_NOEXCEPT)
|
||||
&& is_nothrow_copy_constructible<T>::value
|
||||
&& is_nothrow_destructible<T>::value
|
||||
#else // defined(BOOST_ASIO_HAS_NOEXCEPT)
|
||||
&& is_copy_constructible<T>::value
|
||||
&& is_destructible<T>::value
|
||||
#endif // defined(BOOST_ASIO_HAS_NOEXCEPT)
|
||||
&& traits::equality_comparable<typename decay<T>::type>::is_valid
|
||||
&& traits::equality_comparable<typename decay<T>::type>::is_noexcept
|
||||
>
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
{
|
||||
};
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
|
||||
|
||||
template <typename T>
|
||||
BOOST_ASIO_CONSTEXPR const bool is_executor_v = is_executor<T>::value;
|
||||
|
||||
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_CONCEPTS)
|
||||
|
||||
template <typename T>
|
||||
BOOST_ASIO_CONCEPT executor = is_executor<T>::value;
|
||||
|
||||
#define BOOST_ASIO_EXECUTION_EXECUTOR ::boost::asio::execution::executor
|
||||
|
||||
#else // defined(BOOST_ASIO_HAS_CONCEPTS)
|
||||
|
||||
#define BOOST_ASIO_EXECUTION_EXECUTOR typename
|
||||
|
||||
#endif // defined(BOOST_ASIO_HAS_CONCEPTS)
|
||||
|
||||
} // namespace execution
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_EXECUTION_EXECUTOR_HPP
|
||||
102
include/boost/asio/traits/equality_comparable.hpp
Normal file
102
include/boost/asio/traits/equality_comparable.hpp
Normal file
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// traits/equality_comparable.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 BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
|
||||
#define BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <boost/asio/detail/type_traits.hpp>
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_DECLTYPE) \
|
||||
&& defined(BOOST_ASIO_HAS_NOEXCEPT) \
|
||||
&& defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
|
||||
# define BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT 1
|
||||
#endif // defined(BOOST_ASIO_HAS_DECLTYPE)
|
||||
// && defined(BOOST_ASIO_HAS_NOEXCEPT)
|
||||
// && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
namespace traits {
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct equality_comparable_default;
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct equality_comparable;
|
||||
|
||||
} // namespace traits
|
||||
namespace detail {
|
||||
|
||||
struct no_equality_comparable
|
||||
{
|
||||
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
|
||||
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
|
||||
};
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct equality_comparable_trait : no_equality_comparable
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct equality_comparable_trait<T,
|
||||
typename void_type<
|
||||
decltype(
|
||||
static_cast<bool>(declval<const T>() == declval<const T>()),
|
||||
static_cast<bool>(declval<const T>() != declval<const T>())
|
||||
)
|
||||
>::type>
|
||||
{
|
||||
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
|
||||
|
||||
BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
|
||||
noexcept(declval<const T>() == declval<const T>())
|
||||
&& noexcept(declval<const T>() != declval<const T>()));
|
||||
};
|
||||
|
||||
#else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct equality_comparable_trait :
|
||||
conditional<
|
||||
is_same<T, typename decay<T>::type>::value,
|
||||
no_equality_comparable,
|
||||
traits::equality_comparable<typename decay<T>::type>
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
|
||||
|
||||
} // namespace detail
|
||||
namespace traits {
|
||||
|
||||
template <typename T, typename>
|
||||
struct equality_comparable_default : detail::equality_comparable_trait<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename>
|
||||
struct equality_comparable : equality_comparable_default<T>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
|
||||
Reference in New Issue
Block a user