diff --git a/Jamroot b/Jamroot index 42a0af60..c19b4049 100644 --- a/Jamroot +++ b/Jamroot @@ -144,7 +144,7 @@ import option ; import tools/boost\_install/boost-install ; path-constant BOOST_ROOT : . ; -constant BOOST_VERSION : 1.80.0 ; +constant BOOST_VERSION : 1.82.0 ; constant BOOST_JAMROOT_MODULE : $(__name__) ; # Allow subprojects to simply `import config : requires ;` to get access to the requires rule diff --git a/boost/align/align_up.hpp b/boost/align/align_up.hpp new file mode 100644 index 00000000..84e1a3cb --- /dev/null +++ b/boost/align/align_up.hpp @@ -0,0 +1,27 @@ +/* +Copyright 2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef BOOST_ALIGN_ALIGN_UP_HPP +#define BOOST_ALIGN_ALIGN_UP_HPP + +#include +#include + +namespace boost { +namespace alignment { + +template +BOOST_CONSTEXPR inline typename detail::not_pointer::type +align_up(T value, std::size_t alignment) BOOST_NOEXCEPT +{ + return T((value + (T(alignment) - 1)) & ~T(alignment - 1)); +} + +} /* alignment */ +} /* boost */ + +#endif diff --git a/boost/align/aligned_alloc.hpp b/boost/align/aligned_alloc.hpp index 1d81a133..b5b6bd85 100644 --- a/boost/align/aligned_alloc.hpp +++ b/boost/align/aligned_alloc.hpp @@ -38,7 +38,7 @@ Distributed under the Boost Software License, Version 1.0. #include #elif defined(sun) || defined(__sun) #include -#elif (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) +#elif defined(_POSIX_VERSION) #include #else #include diff --git a/boost/align/detail/align_up.hpp b/boost/align/detail/align_up.hpp new file mode 100644 index 00000000..ac11f896 --- /dev/null +++ b/boost/align/detail/align_up.hpp @@ -0,0 +1,28 @@ +/* +Copyright 2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGN_UP_HPP +#define BOOST_ALIGN_DETAIL_ALIGN_UP_HPP + +#include +#include + +namespace boost { +namespace alignment { + +inline void* +align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT +{ + BOOST_ASSERT(detail::is_alignment(alignment)); + return reinterpret_cast(~(alignment - 1) & + (reinterpret_cast(ptr) + alignment - 1)); +} + +} /* alignment */ +} /* boost */ + +#endif diff --git a/boost/align/detail/not_pointer.hpp b/boost/align/detail/not_pointer.hpp new file mode 100644 index 00000000..12261018 --- /dev/null +++ b/boost/align/detail/not_pointer.hpp @@ -0,0 +1,27 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef BOOST_ALIGN_DETAIL_NOT_POINTER_HPP +#define BOOST_ALIGN_DETAIL_NOT_POINTER_HPP + +namespace boost { +namespace alignment { +namespace detail { + +template +struct not_pointer { + typedef U type; +}; + +template +struct not_pointer { }; + +} /* detail */ +} /* alignment */ +} /* boost */ + +#endif diff --git a/boost/array.hpp b/boost/array.hpp index a32d1e99..f047063d 100644 --- a/boost/array.hpp +++ b/boost/array.hpp @@ -44,8 +44,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/boost/asio.hpp b/boost/asio.hpp index 282fc4c1..1d78a758 100644 --- a/boost/asio.hpp +++ b/boost/asio.hpp @@ -2,7 +2,7 @@ // asio.hpp // ~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -17,11 +17,15 @@ # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) +#include +#include +#include #include #include #include -#include #include +#include +#include #include #include #include @@ -47,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +154,7 @@ #include #include #include +#include #include #include #include @@ -174,6 +181,7 @@ #include #include #include +#include #include #include #include diff --git a/boost/asio/any_completion_executor.hpp b/boost/asio/any_completion_executor.hpp new file mode 100644 index 00000000..a006bbc9 --- /dev/null +++ b/boost/asio/any_completion_executor.hpp @@ -0,0 +1,344 @@ +// +// any_completion_executor.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2023 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_ANY_COMPLETION_EXECUTOR_HPP +#define BOOST_ASIO_ANY_COMPLETION_EXECUTOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include +#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +# include +#else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +# include +#endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) + +#include + +namespace boost { +namespace asio { + +#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) + +typedef executor any_completion_executor; + +#else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) + +/// Polymorphic executor type for use with I/O objects. +/** + * The @c any_completion_executor type is a polymorphic executor that supports + * the set of properties required for the execution of completion handlers. It + * is defined as the execution::any_executor class template parameterised as + * follows: + * @code execution::any_executor< + * execution::prefer_only, + * execution::prefer_only + * execution::prefer_only, + * execution::prefer_only + * > @endcode + */ +class any_completion_executor : +#if defined(GENERATING_DOCUMENTATION) + public execution::any_executor<...> +#else // defined(GENERATING_DOCUMENTATION) + public execution::any_executor< + execution::prefer_only, + execution::prefer_only, + execution::prefer_only, + execution::prefer_only + > +#endif // defined(GENERATING_DOCUMENTATION) +{ +public: +#if !defined(GENERATING_DOCUMENTATION) + typedef execution::any_executor< + execution::prefer_only, + execution::prefer_only, + execution::prefer_only, + execution::prefer_only + > base_type; + + typedef void supportable_properties_type( + execution::prefer_only, + execution::prefer_only, + execution::prefer_only, + execution::prefer_only + ); +#endif // !defined(GENERATING_DOCUMENTATION) + + /// Default constructor. + BOOST_ASIO_DECL any_completion_executor() BOOST_ASIO_NOEXCEPT; + + /// Construct in an empty state. Equivalent effects to default constructor. + BOOST_ASIO_DECL any_completion_executor(nullptr_t) BOOST_ASIO_NOEXCEPT; + + /// Copy constructor. + BOOST_ASIO_DECL any_completion_executor( + const any_completion_executor& e) BOOST_ASIO_NOEXCEPT; + +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move constructor. + BOOST_ASIO_DECL any_completion_executor( + any_completion_executor&& e) BOOST_ASIO_NOEXCEPT; +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + + /// Construct to point to the same target as another any_executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_completion_executor( + execution::any_executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(OtherAnyExecutor e, + typename constraint< + conditional< + !is_same::value + && is_base_of::value, + typename execution::detail::supportable_properties< + 0, supportable_properties_type>::template + is_valid_target, + false_type + >::type::value + >::type = 0) + : base_type(BOOST_ASIO_MOVE_CAST(OtherAnyExecutor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + + /// Construct to point to the same target as another any_executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(std::nothrow_t, + execution::any_executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(std::nothrow_t, OtherAnyExecutor e, + typename constraint< + conditional< + !is_same::value + && is_base_of::value, + typename execution::detail::supportable_properties< + 0, supportable_properties_type>::template + is_valid_target, + false_type + >::type::value + >::type = 0) BOOST_ASIO_NOEXCEPT + : base_type(std::nothrow, BOOST_ASIO_MOVE_CAST(OtherAnyExecutor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + + /// Construct to point to the same target as another any_executor. + BOOST_ASIO_DECL any_completion_executor(std::nothrow_t, + const any_completion_executor& e) BOOST_ASIO_NOEXCEPT; + +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Construct to point to the same target as another any_executor. + BOOST_ASIO_DECL any_completion_executor(std::nothrow_t, + any_completion_executor&& e) BOOST_ASIO_NOEXCEPT; +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + + /// Construct a polymorphic wrapper for the specified executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(Executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(Executor e, + typename constraint< + conditional< + !is_same::value + && !is_base_of::value, + execution::detail::is_valid_target_executor< + Executor, supportable_properties_type>, + false_type + >::type::value + >::type = 0) + : base_type(BOOST_ASIO_MOVE_CAST(Executor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + + /// Construct a polymorphic wrapper for the specified executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(std::nothrow_t, Executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_completion_executor(std::nothrow_t, Executor e, + typename constraint< + conditional< + !is_same::value + && !is_base_of::value, + execution::detail::is_valid_target_executor< + Executor, supportable_properties_type>, + false_type + >::type::value + >::type = 0) BOOST_ASIO_NOEXCEPT + : base_type(std::nothrow, BOOST_ASIO_MOVE_CAST(Executor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + + /// Assignment operator. + BOOST_ASIO_DECL any_completion_executor& operator=( + const any_completion_executor& e) BOOST_ASIO_NOEXCEPT; + +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move assignment operator. + BOOST_ASIO_DECL any_completion_executor& operator=( + any_completion_executor&& e) BOOST_ASIO_NOEXCEPT; +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + + /// Assignment operator that sets the polymorphic wrapper to the empty state. + BOOST_ASIO_DECL any_completion_executor& operator=(nullptr_t); + + /// Destructor. + BOOST_ASIO_DECL ~any_completion_executor(); + + /// Swap targets with another polymorphic wrapper. + BOOST_ASIO_DECL void swap(any_completion_executor& other) BOOST_ASIO_NOEXCEPT; + + /// Obtain a polymorphic wrapper with the specified property. + /** + * Do not call this function directly. It is intended for use with the + * boost::asio::require and boost::asio::prefer customisation points. + * + * For example: + * @code any_completion_executor ex = ...; + * auto ex2 = boost::asio::require(ex, execution::relationship.fork); @endcode + */ + template + any_completion_executor require(const Property& p, + typename constraint< + traits::require_member::is_valid + >::type = 0) const + { + return static_cast(*this).require(p); + } + + /// Obtain a polymorphic wrapper with the specified property. + /** + * Do not call this function directly. It is intended for use with the + * boost::asio::prefer customisation point. + * + * For example: + * @code any_completion_executor ex = ...; + * auto ex2 = boost::asio::prefer(ex, execution::relationship.fork); @endcode + */ + template + any_completion_executor prefer(const Property& p, + typename constraint< + traits::prefer_member::is_valid + >::type = 0) const + { + return static_cast(*this).prefer(p); + } +}; + +#if !defined(GENERATING_DOCUMENTATION) + +template <> +BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer( + const execution::outstanding_work_t::tracked_t&, int) const; + +template <> +BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer( + const execution::outstanding_work_t::untracked_t&, int) const; + +template <> +BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer( + const execution::relationship_t::fork_t&, int) const; + +template <> +BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer( + const execution::relationship_t::continuation_t&, int) const; + +namespace traits { + +#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) + +template <> +struct equality_comparable +{ + static const bool is_valid = true; + static const bool is_noexcept = true; +}; + +#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) + +#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) + +template +struct execute_member +{ + static const bool is_valid = true; + static const bool is_noexcept = false; + 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 : + query_member +{ +}; + +#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT) + +#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) + +template +struct require_member : + require_member +{ + typedef any_completion_executor result_type; +}; + +#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) + +#if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) + +template +struct prefer_member : + prefer_member +{ + typedef any_completion_executor result_type; +}; + +#endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) + +} // namespace traits + +#endif // !defined(GENERATING_DOCUMENTATION) + +#endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) + +} // namespace asio +} // namespace boost + +#include + +#if defined(BOOST_ASIO_HEADER_ONLY) \ + && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +# include +#endif // defined(BOOST_ASIO_HEADER_ONLY) + // && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) + +#endif // BOOST_ASIO_ANY_COMPLETION_EXECUTOR_HPP diff --git a/boost/asio/any_completion_handler.hpp b/boost/asio/any_completion_handler.hpp new file mode 100644 index 00000000..ae73387e --- /dev/null +++ b/boost/asio/any_completion_handler.hpp @@ -0,0 +1,764 @@ +// +// any_completion_handler.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2023 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_ANY_COMPLETION_HANDLER_HPP +#define BOOST_ASIO_ANY_COMPLETION_HANDLER_HPP + +#include + +#if (defined(BOOST_ASIO_HAS_STD_TUPLE) \ + && defined(BOOST_ASIO_HAS_MOVE) \ + && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)) \ + || defined(GENERATING_DOCUMENTATION) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace boost { +namespace asio { +namespace detail { + +class any_completion_handler_impl_base +{ +public: + template + explicit any_completion_handler_impl_base(S&& slot) + : cancel_state_(BOOST_ASIO_MOVE_CAST(S)(slot), enable_total_cancellation()) + { + } + + cancellation_slot get_cancellation_slot() const BOOST_ASIO_NOEXCEPT + { + return cancel_state_.slot(); + } + +private: + cancellation_state cancel_state_; +}; + +template +class any_completion_handler_impl : + public any_completion_handler_impl_base +{ +public: + template + any_completion_handler_impl(S&& slot, H&& h) + : any_completion_handler_impl_base(BOOST_ASIO_MOVE_CAST(S)(slot)), + handler_(BOOST_ASIO_MOVE_CAST(H)(h)) + { + } + + struct uninit_deleter + { + typename std::allocator_traits< + associated_allocator_t>>::template + rebind_alloc alloc; + + void operator()(any_completion_handler_impl* ptr) + { + std::allocator_traits::deallocate(alloc, ptr, 1); + } + }; + + struct deleter + { + typename std::allocator_traits< + associated_allocator_t>>::template + rebind_alloc alloc; + + void operator()(any_completion_handler_impl* ptr) + { + std::allocator_traits::destroy(alloc, ptr); + std::allocator_traits::deallocate(alloc, ptr, 1); + } + }; + + template + static any_completion_handler_impl* create(S&& slot, H&& h) + { + uninit_deleter d{ + (get_associated_allocator)(h, + boost::asio::recycling_allocator())}; + + std::unique_ptr uninit_ptr( + std::allocator_traits::allocate(d.alloc, 1), d); + + any_completion_handler_impl* ptr = + new (uninit_ptr.get()) any_completion_handler_impl( + BOOST_ASIO_MOVE_CAST(S)(slot), BOOST_ASIO_MOVE_CAST(H)(h)); + + uninit_ptr.release(); + return ptr; + } + + void destroy() + { + deleter d{ + (get_associated_allocator)(handler_, + boost::asio::recycling_allocator())}; + + d(this); + } + + any_completion_executor executor( + const any_completion_executor& candidate) const BOOST_ASIO_NOEXCEPT + { + return any_completion_executor(std::nothrow, + (get_associated_executor)(handler_, candidate)); + } + + void* allocate(std::size_t size, std::size_t align) const + { + typename std::allocator_traits< + associated_allocator_t>>::template + rebind_alloc alloc( + (get_associated_allocator)(handler_, + boost::asio::recycling_allocator())); + + std::size_t space = size + align - 1; + unsigned char* base = + std::allocator_traits::allocate( + alloc, space + sizeof(std::ptrdiff_t)); + + void* p = base; + if (detail::align(align, size, p, space)) + { + std::ptrdiff_t off = static_cast(p) - base; + std::memcpy(static_cast(p) + size, &off, sizeof(off)); + return p; + } + + std::bad_alloc ex; + boost::asio::detail::throw_exception(ex); + return nullptr; + } + + void deallocate(void* p, std::size_t size, std::size_t align) const + { + if (p) + { + typename std::allocator_traits< + associated_allocator_t>>::template + rebind_alloc alloc( + (get_associated_allocator)(handler_, + boost::asio::recycling_allocator())); + + std::ptrdiff_t off; + std::memcpy(&off, static_cast(p) + size, sizeof(off)); + unsigned char* base = static_cast(p) - off; + + std::allocator_traits::deallocate( + alloc, base, size + align -1 + sizeof(std::ptrdiff_t)); + } + } + + template + void call(Args&&... args) + { + deleter d{ + (get_associated_allocator)(handler_, + boost::asio::recycling_allocator())}; + + std::unique_ptr ptr(this, d); + Handler handler(BOOST_ASIO_MOVE_CAST(Handler)(handler_)); + ptr.reset(); + + BOOST_ASIO_MOVE_CAST(Handler)(handler)( + BOOST_ASIO_MOVE_CAST(Args)(args)...); + } + +private: + Handler handler_; +}; + +template +class any_completion_handler_call_fn; + +template +class any_completion_handler_call_fn +{ +public: + using type = void(*)(any_completion_handler_impl_base*, Args...); + + constexpr any_completion_handler_call_fn(type fn) + : call_fn_(fn) + { + } + + void call(any_completion_handler_impl_base* impl, Args... args) const + { + call_fn_(impl, BOOST_ASIO_MOVE_CAST(Args)(args)...); + } + + template + static void impl(any_completion_handler_impl_base* impl, Args... args) + { + static_cast*>(impl)->call( + BOOST_ASIO_MOVE_CAST(Args)(args)...); + } + +private: + type call_fn_; +}; + +template +class any_completion_handler_call_fns; + +template +class any_completion_handler_call_fns : + public any_completion_handler_call_fn +{ +public: + using any_completion_handler_call_fn< + Signature>::any_completion_handler_call_fn; + using any_completion_handler_call_fn::call; +}; + +template +class any_completion_handler_call_fns : + public any_completion_handler_call_fn, + public any_completion_handler_call_fns +{ +public: + template + constexpr any_completion_handler_call_fns(CallFn fn, CallFns... fns) + : any_completion_handler_call_fn(fn), + any_completion_handler_call_fns(fns...) + { + } + + using any_completion_handler_call_fn::call; + using any_completion_handler_call_fns::call; +}; + +class any_completion_handler_destroy_fn +{ +public: + using type = void(*)(any_completion_handler_impl_base*); + + constexpr any_completion_handler_destroy_fn(type fn) + : destroy_fn_(fn) + { + } + + void destroy(any_completion_handler_impl_base* impl) const + { + destroy_fn_(impl); + } + + template + static void impl(any_completion_handler_impl_base* impl) + { + static_cast*>(impl)->destroy(); + } + +private: + type destroy_fn_; +}; + +class any_completion_handler_executor_fn +{ +public: + using type = any_completion_executor(*)( + any_completion_handler_impl_base*, const any_completion_executor&); + + constexpr any_completion_handler_executor_fn(type fn) + : executor_fn_(fn) + { + } + + any_completion_executor executor(any_completion_handler_impl_base* impl, + const any_completion_executor& candidate) const + { + return executor_fn_(impl, candidate); + } + + template + static any_completion_executor impl(any_completion_handler_impl_base* impl, + const any_completion_executor& candidate) + { + return static_cast*>(impl)->executor( + candidate); + } + +private: + type executor_fn_; +}; + +class any_completion_handler_allocate_fn +{ +public: + using type = void*(*)(any_completion_handler_impl_base*, + std::size_t, std::size_t); + + constexpr any_completion_handler_allocate_fn(type fn) + : allocate_fn_(fn) + { + } + + void* allocate(any_completion_handler_impl_base* impl, + std::size_t size, std::size_t align) const + { + return allocate_fn_(impl, size, align); + } + + template + static void* impl(any_completion_handler_impl_base* impl, + std::size_t size, std::size_t align) + { + return static_cast*>(impl)->allocate( + size, align); + } + +private: + type allocate_fn_; +}; + +class any_completion_handler_deallocate_fn +{ +public: + using type = void(*)(any_completion_handler_impl_base*, + void*, std::size_t, std::size_t); + + constexpr any_completion_handler_deallocate_fn(type fn) + : deallocate_fn_(fn) + { + } + + void deallocate(any_completion_handler_impl_base* impl, + void* p, std::size_t size, std::size_t align) const + { + deallocate_fn_(impl, p, size, align); + } + + template + static void impl(any_completion_handler_impl_base* impl, + void* p, std::size_t size, std::size_t align) + { + static_cast*>(impl)->deallocate( + p, size, align); + } + +private: + type deallocate_fn_; +}; + +template +class any_completion_handler_fn_table + : private any_completion_handler_destroy_fn, + private any_completion_handler_executor_fn, + private any_completion_handler_allocate_fn, + private any_completion_handler_deallocate_fn, + private any_completion_handler_call_fns +{ +public: + template + constexpr any_completion_handler_fn_table( + any_completion_handler_destroy_fn::type destroy_fn, + any_completion_handler_executor_fn::type executor_fn, + any_completion_handler_allocate_fn::type allocate_fn, + any_completion_handler_deallocate_fn::type deallocate_fn, + CallFns... call_fns) + : any_completion_handler_destroy_fn(destroy_fn), + any_completion_handler_executor_fn(executor_fn), + any_completion_handler_allocate_fn(allocate_fn), + any_completion_handler_deallocate_fn(deallocate_fn), + any_completion_handler_call_fns(call_fns...) + { + } + + using any_completion_handler_destroy_fn::destroy; + using any_completion_handler_executor_fn::executor; + using any_completion_handler_allocate_fn::allocate; + using any_completion_handler_deallocate_fn::deallocate; + using any_completion_handler_call_fns::call; +}; + +template +struct any_completion_handler_fn_table_instance +{ + static constexpr any_completion_handler_fn_table + value = any_completion_handler_fn_table( + &any_completion_handler_destroy_fn::impl, + &any_completion_handler_executor_fn::impl, + &any_completion_handler_allocate_fn::impl, + &any_completion_handler_deallocate_fn::impl, + &any_completion_handler_call_fn::template impl...); +}; + +template +constexpr any_completion_handler_fn_table +any_completion_handler_fn_table_instance::value; + +} // namespace detail + +template +class any_completion_handler; + +/// An allocator type that forwards memory allocation operations through an +/// instance of @c any_completion_handler. +template +class any_completion_handler_allocator +{ +private: + template + friend class any_completion_handler; + + template + friend class any_completion_handler_allocator; + + const detail::any_completion_handler_fn_table* fn_table_; + detail::any_completion_handler_impl_base* impl_; + + constexpr any_completion_handler_allocator(int, + const any_completion_handler& h) BOOST_ASIO_NOEXCEPT + : fn_table_(h.fn_table_), + impl_(h.impl_) + { + } + +public: + /// The type of objects that may be allocated by the allocator. + typedef T value_type; + + /// Rebinds an allocator to another value type. + template + struct rebind + { + /// Specifies the type of the rebound allocator. + typedef any_completion_handler_allocator other; + }; + + /// Construct from another @c any_completion_handler_allocator. + template + constexpr any_completion_handler_allocator( + const any_completion_handler_allocator& a) + BOOST_ASIO_NOEXCEPT + : fn_table_(a.fn_table_), + impl_(a.impl_) + { + } + + /// Equality operator. + constexpr bool operator==( + const any_completion_handler_allocator& other) const BOOST_ASIO_NOEXCEPT + { + return fn_table_ == other.fn_table_ && impl_ == other.impl_; + } + + /// Inequality operator. + constexpr bool operator!=( + const any_completion_handler_allocator& other) const BOOST_ASIO_NOEXCEPT + { + return fn_table_ != other.fn_table_ || impl_ != other.impl_; + } + + /// Allocate space for @c n objects of the allocator's value type. + T* allocate(std::size_t n) const + { + return static_cast( + fn_table_->allocate( + impl_, sizeof(T) * n, alignof(T))); + } + + /// Deallocate space for @c n objects of the allocator's value type. + void deallocate(T* p, std::size_t n) const + { + fn_table_->deallocate(impl_, p, sizeof(T) * n, alignof(T)); + } +}; + +/// A protoco-allocator type that may be rebound to obtain an allocator that +/// forwards memory allocation operations through an instance of +/// @c any_completion_handler. +template +class any_completion_handler_allocator +{ +private: + template + friend class any_completion_handler; + + template + friend class any_completion_handler_allocator; + + const detail::any_completion_handler_fn_table* fn_table_; + detail::any_completion_handler_impl_base* impl_; + + constexpr any_completion_handler_allocator(int, + const any_completion_handler& h) BOOST_ASIO_NOEXCEPT + : fn_table_(h.fn_table_), + impl_(h.impl_) + { + } + +public: + /// @c void as no objects can be allocated through a proto-allocator. + typedef void value_type; + + /// Rebinds an allocator to another value type. + template + struct rebind + { + /// Specifies the type of the rebound allocator. + typedef any_completion_handler_allocator other; + }; + + /// Construct from another @c any_completion_handler_allocator. + template + constexpr any_completion_handler_allocator( + const any_completion_handler_allocator& a) + BOOST_ASIO_NOEXCEPT + : fn_table_(a.fn_table_), + impl_(a.impl_) + { + } + + /// Equality operator. + constexpr bool operator==( + const any_completion_handler_allocator& other) const BOOST_ASIO_NOEXCEPT + { + return fn_table_ == other.fn_table_ && impl_ == other.impl_; + } + + /// Inequality operator. + constexpr bool operator!=( + const any_completion_handler_allocator& other) const BOOST_ASIO_NOEXCEPT + { + return fn_table_ != other.fn_table_ || impl_ != other.impl_; + } +}; + +/// Polymorphic wrapper for completion handlers. +/** + * The @c any_completion_handler class template is a polymorphic wrapper for + * completion handlers that propagates the associated executor, associated + * allocator, and associated cancellation slot through a type-erasing interface. + * + * When using @c any_completion_handler, specify one or more completion + * signatures as template parameters. These will dictate the arguments that may + * be passed to the handler through the polymorphic interface. + * + * Typical uses for @c any_completion_handler include: + * + * @li Separate compilation of asynchronous operation implementations. + * + * @li Enabling interoperability between asynchronous operations and virtual + * functions. + */ +template +class any_completion_handler +{ +#if !defined(GENERATING_DOCUMENTATION) +private: + template + friend class any_completion_handler_allocator; + + template + friend struct associated_executor; + + const detail::any_completion_handler_fn_table* fn_table_; + detail::any_completion_handler_impl_base* impl_; +#endif // !defined(GENERATING_DOCUMENTATION) + +public: + /// The associated allocator type. + using allocator_type = any_completion_handler_allocator; + + /// The associated cancellation slot type. + using cancellation_slot_type = cancellation_slot; + + /// Construct an @c any_completion_handler in an empty state, without a target + /// object. + constexpr any_completion_handler() + : fn_table_(nullptr), + impl_(nullptr) + { + } + + /// Construct an @c any_completion_handler in an empty state, without a target + /// object. + constexpr any_completion_handler(nullptr_t) + : fn_table_(nullptr), + impl_(nullptr) + { + } + + /// Construct an @c any_completion_handler to contain the specified target. + template ::type> + any_completion_handler(H&& h, + typename constraint< + !is_same::type, any_completion_handler>::value + >::type = 0) + : fn_table_( + &detail::any_completion_handler_fn_table_instance< + Handler, Signatures...>::value), + impl_(detail::any_completion_handler_impl::create( + (get_associated_cancellation_slot)(h), BOOST_ASIO_MOVE_CAST(H)(h))) + { + } + + /// Move-construct an @c any_completion_handler from another. + /** + * After the operation, the moved-from object @c other has no target. + */ + any_completion_handler(any_completion_handler&& other) BOOST_ASIO_NOEXCEPT + : fn_table_(other.fn_table_), + impl_(other.impl_) + { + other.fn_table_ = nullptr; + other.impl_ = nullptr; + } + + /// Move-assign an @c any_completion_handler from another. + /** + * After the operation, the moved-from object @c other has no target. + */ + any_completion_handler& operator=( + any_completion_handler&& other) BOOST_ASIO_NOEXCEPT + { + any_completion_handler( + BOOST_ASIO_MOVE_CAST(any_completion_handler)(other)).swap(*this); + return *this; + } + + /// Assignment operator that sets the polymorphic wrapper to the empty state. + any_completion_handler& operator=(nullptr_t) BOOST_ASIO_NOEXCEPT + { + any_completion_handler().swap(*this); + return *this; + } + + /// Destructor. + ~any_completion_handler() + { + if (impl_) + fn_table_->destroy(impl_); + } + + /// Test if the polymorphic wrapper is empty. + constexpr explicit operator bool() const BOOST_ASIO_NOEXCEPT + { + return impl_ != nullptr; + } + + /// Test if the polymorphic wrapper is non-empty. + constexpr bool operator!() const BOOST_ASIO_NOEXCEPT + { + return impl_ == nullptr; + } + + /// Swap the content of an @c any_completion_handler with another. + void swap(any_completion_handler& other) BOOST_ASIO_NOEXCEPT + { + std::swap(fn_table_, other.fn_table_); + std::swap(impl_, other.impl_); + } + + /// Get the associated allocator. + allocator_type get_allocator() const BOOST_ASIO_NOEXCEPT + { + return allocator_type(0, *this); + } + + /// Get the associated cancellation slot. + cancellation_slot_type get_cancellation_slot() const BOOST_ASIO_NOEXCEPT + { + return impl_->get_cancellation_slot(); + } + + /// Function call operator. + /** + * Invokes target completion handler with the supplied arguments. + * + * This function may only be called once, as the target handler is moved from. + * The polymorphic wrapper is left in an empty state. + * + * Throws @c std::bad_function_call if the polymorphic wrapper is empty. + */ + template + auto operator()(Args&&... args) + -> decltype(fn_table_->call(impl_, BOOST_ASIO_MOVE_CAST(Args)(args)...)) + { + if (detail::any_completion_handler_impl_base* impl = impl_) + { + impl_ = nullptr; + return fn_table_->call(impl, BOOST_ASIO_MOVE_CAST(Args)(args)...); + } + std::bad_function_call ex; + boost::asio::detail::throw_exception(ex); + } + + /// Equality operator. + friend constexpr bool operator==( + const any_completion_handler& a, nullptr_t) BOOST_ASIO_NOEXCEPT + { + return a.impl_ == nullptr; + } + + /// Equality operator. + friend constexpr bool operator==( + nullptr_t, const any_completion_handler& b) BOOST_ASIO_NOEXCEPT + { + return nullptr == b.impl_; + } + + /// Inequality operator. + friend constexpr bool operator!=( + const any_completion_handler& a, nullptr_t) BOOST_ASIO_NOEXCEPT + { + return a.impl_ != nullptr; + } + + /// Inequality operator. + friend constexpr bool operator!=( + nullptr_t, const any_completion_handler& b) BOOST_ASIO_NOEXCEPT + { + return nullptr != b.impl_; + } +}; + +template +struct associated_executor, Candidate> +{ + using type = any_completion_executor; + + static type get(const any_completion_handler& handler, + const Candidate& candidate = Candidate()) BOOST_ASIO_NOEXCEPT + { + return handler.fn_table_->executor(handler.impl_, + any_completion_executor(std::nothrow, candidate)); + } +}; + +} // namespace asio +} // namespace boost + +#include + +#endif // (defined(BOOST_ASIO_HAS_STD_TUPLE) + // && defined(BOOST_ASIO_HAS_MOVE) + // && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)) + // || defined(GENERATING_DOCUMENTATION) + +#endif // BOOST_ASIO_ANY_COMPLETION_HANDLER_HPP diff --git a/boost/asio/any_io_executor.hpp b/boost/asio/any_io_executor.hpp index 6dc8731f..12e0008b 100644 --- a/boost/asio/any_io_executor.hpp +++ b/boost/asio/any_io_executor.hpp @@ -2,7 +2,7 @@ // any_io_executor.hpp // ~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -124,6 +124,40 @@ public: } #endif // defined(GENERATING_DOCUMENTATION) + /// Construct to point to the same target as another any_executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_io_executor(std::nothrow_t, + execution::any_executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_io_executor(std::nothrow_t, OtherAnyExecutor e, + typename constraint< + conditional< + !is_same::value + && is_base_of::value, + typename execution::detail::supportable_properties< + 0, supportable_properties_type>::template + is_valid_target, + false_type + >::type::value + >::type = 0) BOOST_ASIO_NOEXCEPT + : base_type(std::nothrow, BOOST_ASIO_MOVE_CAST(OtherAnyExecutor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + + /// Construct to point to the same target as another any_executor. + BOOST_ASIO_DECL any_io_executor(std::nothrow_t, + const any_io_executor& e) BOOST_ASIO_NOEXCEPT; + +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Construct to point to the same target as another any_executor. + BOOST_ASIO_DECL any_io_executor(std::nothrow_t, + any_io_executor&& e) BOOST_ASIO_NOEXCEPT; +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Construct a polymorphic wrapper for the specified executor. #if defined(GENERATING_DOCUMENTATION) template @@ -146,6 +180,28 @@ public: } #endif // defined(GENERATING_DOCUMENTATION) + /// Construct a polymorphic wrapper for the specified executor. +#if defined(GENERATING_DOCUMENTATION) + template + any_io_executor(std::nothrow_t, Executor e); +#else // defined(GENERATING_DOCUMENTATION) + template + any_io_executor(std::nothrow_t, Executor e, + typename constraint< + conditional< + !is_same::value + && !is_base_of::value, + execution::detail::is_valid_target_executor< + Executor, supportable_properties_type>, + false_type + >::type::value + >::type = 0) BOOST_ASIO_NOEXCEPT + : base_type(std::nothrow, BOOST_ASIO_MOVE_CAST(Executor)(e)) + { + } +#endif // defined(GENERATING_DOCUMENTATION) + /// Assignment operator. BOOST_ASIO_DECL any_io_executor& operator=( const any_io_executor& e) BOOST_ASIO_NOEXCEPT; diff --git a/boost/asio/append.hpp b/boost/asio/append.hpp index 0963236f..7b34641c 100644 --- a/boost/asio/append.hpp +++ b/boost/asio/append.hpp @@ -2,7 +2,7 @@ // append.hpp // ~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) diff --git a/boost/asio/as_tuple.hpp b/boost/asio/as_tuple.hpp index 613fe1ad..03aeac1e 100644 --- a/boost/asio/as_tuple.hpp +++ b/boost/asio/as_tuple.hpp @@ -2,7 +2,7 @@ // as_tuple.hpp // ~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) diff --git a/boost/asio/associated_allocator.hpp b/boost/asio/associated_allocator.hpp index 01c02026..50cc9c45 100644 --- a/boost/asio/associated_allocator.hpp +++ b/boost/asio/associated_allocator.hpp @@ -2,7 +2,7 @@ // associated_allocator.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -43,37 +43,53 @@ struct has_allocator_type +template struct associated_allocator_impl { - typedef E type; + typedef void asio_associated_allocator_is_unspecialised; - static type get(const T&, const E& e) BOOST_ASIO_NOEXCEPT + typedef A type; + + static type get(const T&) BOOST_ASIO_NOEXCEPT { - return e; + return type(); + } + + static const type& get(const T&, const A& a) BOOST_ASIO_NOEXCEPT + { + return a; } }; -template -struct associated_allocator_impl +struct associated_allocator_impl::type> { typedef typename T::allocator_type type; - static type get(const T& t, const E&) BOOST_ASIO_NOEXCEPT + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + const T& t) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX((t.get_allocator())) + { + return t.get_allocator(); + } + + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + const T& t, const A&) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX((t.get_allocator())) { return t.get_allocator(); } }; -template -struct associated_allocator_impl +struct associated_allocator_impl::value >::type, typename void_type< - typename associator::type - >::type> : associator + typename associator::type + >::type> : associator { }; @@ -93,29 +109,32 @@ struct associated_allocator_impl > struct associated_allocator +#if !defined(GENERATING_DOCUMENTATION) + : detail::associated_allocator_impl +#endif // !defined(GENERATING_DOCUMENTATION) { +#if defined(GENERATING_DOCUMENTATION) /// If @c T has a nested type @c allocator_type, T::allocator_type. /// Otherwise @c Allocator. -#if defined(GENERATING_DOCUMENTATION) typedef see_below type; -#else // defined(GENERATING_DOCUMENTATION) - typedef typename detail::associated_allocator_impl::type type; -#endif // defined(GENERATING_DOCUMENTATION) + + /// If @c T has a nested type @c allocator_type, returns + /// t.get_allocator(). Otherwise returns @c type(). + static decltype(auto) get(const T& t) BOOST_ASIO_NOEXCEPT; /// If @c T has a nested type @c allocator_type, returns /// t.get_allocator(). Otherwise returns @c a. - static type get(const T& t, - const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT - { - return detail::associated_allocator_impl::get(t, a); - } + static decltype(auto) get(const T& t, const Allocator& a) BOOST_ASIO_NOEXCEPT; +#endif // defined(GENERATING_DOCUMENTATION) }; /// Helper function to obtain an object's associated allocator. @@ -134,8 +153,11 @@ get_associated_allocator(const T& t) BOOST_ASIO_NOEXCEPT * @returns associated_allocator::get(t, a) */ template -BOOST_ASIO_NODISCARD inline typename associated_allocator::type +BOOST_ASIO_NODISCARD inline BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX2( + typename associated_allocator::type) get_associated_allocator(const T& t, const Allocator& a) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_allocator::get(t, a))) { return associated_allocator::get(t, a); } @@ -148,12 +170,37 @@ using associated_allocator_t #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) +namespace detail { + +template +struct associated_allocator_forwarding_base +{ +}; + +template +struct associated_allocator_forwarding_base::asio_associated_allocator_is_unspecialised, + void + >::value + >::type> +{ + typedef void asio_associated_allocator_is_unspecialised; +}; + +} // namespace detail + #if defined(BOOST_ASIO_HAS_STD_REFERENCE_WRAPPER) \ || defined(GENERATING_DOCUMENTATION) /// Specialisation of associated_allocator for @c std::reference_wrapper. template struct associated_allocator, Allocator> +#if !defined(GENERATING_DOCUMENTATION) + : detail::associated_allocator_forwarding_base +#endif // !defined(GENERATING_DOCUMENTATION) { /// Forwards @c type to the associator specialisation for the unwrapped type /// @c T. @@ -161,8 +208,17 @@ struct associated_allocator, Allocator> /// Forwards the request to get the allocator to the associator specialisation /// for the unwrapped type @c T. - static type get(reference_wrapper t, - const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT + static type get(reference_wrapper t) BOOST_ASIO_NOEXCEPT + { + return associated_allocator::get(t.get()); + } + + /// Forwards the request to get the allocator to the associator specialisation + /// for the unwrapped type @c T. + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + reference_wrapper t, const Allocator& a) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_allocator::get(t.get(), a))) { return associated_allocator::get(t.get(), a); } diff --git a/boost/asio/associated_cancellation_slot.hpp b/boost/asio/associated_cancellation_slot.hpp index f3f52e73..ab55354f 100644 --- a/boost/asio/associated_cancellation_slot.hpp +++ b/boost/asio/associated_cancellation_slot.hpp @@ -2,7 +2,7 @@ // associated_cancellation_slot.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,12 @@ struct associated_cancellation_slot_impl typedef S type; - static type get(const T&, const S& s = S()) BOOST_ASIO_NOEXCEPT + static type get(const T&) BOOST_ASIO_NOEXCEPT + { + return type(); + } + + static const type& get(const T&, const S& s) BOOST_ASIO_NOEXCEPT { return s; } @@ -61,7 +67,16 @@ struct associated_cancellation_slot_impl struct associated_cancellation_slot @@ -111,10 +128,14 @@ struct associated_cancellation_slot /// @c CancellationSlot. typedef see_below type; + /// If @c T has a nested type @c cancellation_slot_type, returns + /// t.get_cancellation_slot(). Otherwise returns @c type(). + static decltype(auto) get(const T& t) BOOST_ASIO_NOEXCEPT; + /// If @c T has a nested type @c cancellation_slot_type, returns /// t.get_cancellation_slot(). Otherwise returns @c s. - static type get(const T& t, - const CancellationSlot& s = CancellationSlot()) BOOST_ASIO_NOEXCEPT; + static decltype(auto) get(const T& t, + const CancellationSlot& s) BOOST_ASIO_NOEXCEPT; #endif // defined(GENERATING_DOCUMENTATION) }; @@ -135,10 +156,12 @@ get_associated_cancellation_slot(const T& t) BOOST_ASIO_NOEXCEPT * CancellationSlot>::get(t, st) */ template -BOOST_ASIO_NODISCARD inline -typename associated_cancellation_slot::type +BOOST_ASIO_NODISCARD inline BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX2( + typename associated_cancellation_slot::type) get_associated_cancellation_slot(const T& t, const CancellationSlot& st) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_cancellation_slot::get(t, st))) { return associated_cancellation_slot::get(t, st); } @@ -172,6 +195,43 @@ struct associated_cancellation_slot_forwarding_base +struct associated_cancellation_slot, CancellationSlot> +#if !defined(GENERATING_DOCUMENTATION) + : detail::associated_cancellation_slot_forwarding_base +#endif // !defined(GENERATING_DOCUMENTATION) +{ + /// Forwards @c type to the associator specialisation for the unwrapped type + /// @c T. + typedef typename associated_cancellation_slot::type type; + + /// Forwards the request to get the cancellation slot to the associator + /// specialisation for the unwrapped type @c T. + static type get(reference_wrapper t) BOOST_ASIO_NOEXCEPT + { + return associated_cancellation_slot::get(t.get()); + } + + /// Forwards the request to get the cancellation slot to the associator + /// specialisation for the unwrapped type @c T. + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get(reference_wrapper t, + const CancellationSlot& s) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_cancellation_slot::get(t.get(), s))) + { + return associated_cancellation_slot::get(t.get(), s); + } +}; + +#endif // defined(BOOST_ASIO_HAS_STD_REFERENCE_WRAPPER) + // || defined(GENERATING_DOCUMENTATION) + } // namespace asio } // namespace boost diff --git a/boost/asio/associated_executor.hpp b/boost/asio/associated_executor.hpp index 02738aac..4ffc80f9 100644 --- a/boost/asio/associated_executor.hpp +++ b/boost/asio/associated_executor.hpp @@ -2,7 +2,7 @@ // associated_executor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -52,7 +52,12 @@ struct associated_executor_impl typedef E type; - static type get(const T&, const E& e = E()) BOOST_ASIO_NOEXCEPT + static type get(const T&) BOOST_ASIO_NOEXCEPT + { + return type(); + } + + static const type& get(const T&, const E& e) BOOST_ASIO_NOEXCEPT { return e; } @@ -64,7 +69,16 @@ struct associated_executor_impl struct associated_executor @@ -113,10 +129,13 @@ struct associated_executor /// Otherwise @c Executor. typedef see_below type; + /// If @c T has a nested type @c executor_type, returns + /// t.get_executor(). Otherwise returns @c type(). + static decltype(auto) get(const T& t) BOOST_ASIO_NOEXCEPT; + /// If @c T has a nested type @c executor_type, returns /// t.get_executor(). Otherwise returns @c ex. - static type get(const T& t, - const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT; + static decltype(auto) get(const T& t, const Executor& ex) BOOST_ASIO_NOEXCEPT; #endif // defined(GENERATING_DOCUMENTATION) }; @@ -136,11 +155,14 @@ get_associated_executor(const T& t) BOOST_ASIO_NOEXCEPT * @returns associated_executor::get(t, ex) */ template -BOOST_ASIO_NODISCARD inline typename associated_executor::type +BOOST_ASIO_NODISCARD inline BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX2( + typename associated_executor::type) get_associated_executor(const T& t, const Executor& ex, typename constraint< is_executor::value || execution::is_executor::value >::type = 0) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_executor::get(t, ex))) { return associated_executor::get(t, ex); } @@ -152,7 +174,7 @@ get_associated_executor(const T& t, const Executor& ex, */ template BOOST_ASIO_NODISCARD inline typename associated_executor::type + typename ExecutionContext::executor_type>::type get_associated_executor(const T& t, ExecutionContext& ctx, typename constraint::value>::type = 0) BOOST_ASIO_NOEXCEPT @@ -206,8 +228,17 @@ struct associated_executor, Executor> /// Forwards the request to get the executor to the associator specialisation /// for the unwrapped type @c T. - static type get(reference_wrapper t, - const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT + static type get(reference_wrapper t) BOOST_ASIO_NOEXCEPT + { + return associated_executor::get(t.get()); + } + + /// Forwards the request to get the executor to the associator specialisation + /// for the unwrapped type @c T. + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + reference_wrapper t, const Executor& ex) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_executor::get(t.get(), ex))) { return associated_executor::get(t.get(), ex); } diff --git a/boost/asio/associated_immediate_executor.hpp b/boost/asio/associated_immediate_executor.hpp new file mode 100644 index 00000000..d73d395f --- /dev/null +++ b/boost/asio/associated_immediate_executor.hpp @@ -0,0 +1,299 @@ +// +// associated_immediate_executor.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2023 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_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP +#define BOOST_ASIO_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace boost { +namespace asio { + +template +struct associated_immediate_executor; + +namespace detail { + +template +struct has_immediate_executor_type : false_type +{ +}; + +template +struct has_immediate_executor_type::type> + : true_type +{ +}; + +template +struct default_immediate_executor +{ + typedef typename require_result::type type; + + static type get(const E& e) BOOST_ASIO_NOEXCEPT + { + return boost::asio::require(e, execution::blocking.never); + } +}; + +template +struct default_immediate_executor::value + >::type, + typename enable_if< + is_executor::value + >::type> +{ + class type : public E + { + public: + template + explicit type(const Executor1& e, + typename constraint< + conditional< + !is_same::value, + is_convertible, + false_type + >::type::value + >::type = 0) BOOST_ASIO_NOEXCEPT + : E(e) + { + } + + type(const type& other) BOOST_ASIO_NOEXCEPT + : E(static_cast(other)) + { + } + +#if defined(BOOST_ASIO_HAS_MOVE) + type(type&& other) BOOST_ASIO_NOEXCEPT + : E(BOOST_ASIO_MOVE_CAST(E)(other)) + { + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + + template + void dispatch(BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const + { + this->post(BOOST_ASIO_MOVE_CAST(Function)(f), a); + } + + friend bool operator==(const type& a, const type& b) BOOST_ASIO_NOEXCEPT + { + return static_cast(a) == static_cast(b); + } + + friend bool operator!=(const type& a, const type& b) BOOST_ASIO_NOEXCEPT + { + return static_cast(a) != static_cast(b); + } + }; + + static type get(const E& e) BOOST_ASIO_NOEXCEPT + { + return type(e); + } +}; + +template +struct associated_immediate_executor_impl +{ + typedef void asio_associated_immediate_executor_is_unspecialised; + + typedef typename default_immediate_executor::type type; + + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + const T&, const E& e) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX((default_immediate_executor::get(e))) + { + return default_immediate_executor::get(e); + } +}; + +template +struct associated_immediate_executor_impl::type> +{ + typedef typename T::immediate_executor_type type; + + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + const T& t, const E&) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX((t.get_immediate_executor())) + { + return t.get_immediate_executor(); + } +}; + +template +struct associated_immediate_executor_impl::value + >::type, + typename void_type< + typename associator::type + >::type> : associator +{ +}; + +} // namespace detail + +/// Traits type used to obtain the immediate executor associated with an object. +/** + * A program may specialise this traits type if the @c T template parameter in + * the specialisation is a user-defined type. The template parameter @c + * Executor shall be a type meeting the Executor requirements. + * + * Specialisations shall meet the following requirements, where @c t is a const + * reference to an object of type @c T, and @c e is an object of type @c + * Executor. + * + * @li Provide a nested typedef @c type that identifies a type meeting the + * Executor requirements. + * + * @li Provide a noexcept static member function named @c get, callable as @c + * get(t) and with return type @c type or a (possibly const) reference to @c + * type. + * + * @li Provide a noexcept static member function named @c get, callable as @c + * get(t,e) and with return type @c type or a (possibly const) reference to @c + * type. + */ +template +struct associated_immediate_executor +#if !defined(GENERATING_DOCUMENTATION) + : detail::associated_immediate_executor_impl +#endif // !defined(GENERATING_DOCUMENTATION) +{ +#if defined(GENERATING_DOCUMENTATION) + /// If @c T has a nested type @c immediate_executor_type, + // T::immediate_executor_type. Otherwise @c Executor. + typedef see_below type; + + /// If @c T has a nested type @c immediate_executor_type, returns + /// t.get_immediate_executor(). Otherwise returns + /// boost::asio::require(ex, boost::asio::execution::blocking.never). + static decltype(auto) get(const T& t, const Executor& ex) BOOST_ASIO_NOEXCEPT; +#endif // defined(GENERATING_DOCUMENTATION) +}; + +/// Helper function to obtain an object's associated executor. +/** + * @returns associated_immediate_executor::get(t, ex) + */ +template +BOOST_ASIO_NODISCARD inline BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX2( + typename associated_immediate_executor::type) +get_associated_immediate_executor(const T& t, const Executor& ex, + typename constraint< + is_executor::value || execution::is_executor::value + >::type = 0) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_immediate_executor::get(t, ex))) +{ + return associated_immediate_executor::get(t, ex); +} + +/// Helper function to obtain an object's associated executor. +/** + * @returns associated_immediate_executor::get(t, ctx.get_executor()) + */ +template +BOOST_ASIO_NODISCARD inline typename associated_immediate_executor::type +get_associated_immediate_executor(const T& t, ExecutionContext& ctx, + typename constraint::value>::type = 0) BOOST_ASIO_NOEXCEPT +{ + return associated_immediate_executor::get(t, ctx.get_executor()); +} + +#if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) + +template +using associated_immediate_executor_t = + typename associated_immediate_executor::type; + +#endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) + +namespace detail { + +template +struct associated_immediate_executor_forwarding_base +{ +}; + +template +struct associated_immediate_executor_forwarding_base::asio_associated_immediate_executor_is_unspecialised, + void + >::value + >::type> +{ + typedef void asio_associated_immediate_executor_is_unspecialised; +}; + +} // namespace detail + +#if defined(BOOST_ASIO_HAS_STD_REFERENCE_WRAPPER) \ + || defined(GENERATING_DOCUMENTATION) + +/// Specialisation of associated_immediate_executor for +/// @c std::reference_wrapper. +template +struct associated_immediate_executor, Executor> +#if !defined(GENERATING_DOCUMENTATION) + : detail::associated_immediate_executor_forwarding_base +#endif // !defined(GENERATING_DOCUMENTATION) +{ + /// Forwards @c type to the associator specialisation for the unwrapped type + /// @c T. + typedef typename associated_immediate_executor::type type; + + /// Forwards the request to get the executor to the associator specialisation + /// for the unwrapped type @c T. + static BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(type) get( + reference_wrapper t, const Executor& ex) BOOST_ASIO_NOEXCEPT + BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(( + associated_immediate_executor::get(t.get(), ex))) + { + return associated_immediate_executor::get(t.get(), ex); + } +}; + +#endif // defined(BOOST_ASIO_HAS_STD_REFERENCE_WRAPPER) + // || defined(GENERATING_DOCUMENTATION) + +} // namespace asio +} // namespace boost + +#include + +#endif // BOOST_ASIO_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP diff --git a/boost/asio/associator.hpp b/boost/asio/associator.hpp index bc775b01..b0b5b44c 100644 --- a/boost/asio/associator.hpp +++ b/boost/asio/associator.hpp @@ -2,7 +2,7 @@ // associator.hpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) diff --git a/boost/asio/async_result.hpp b/boost/asio/async_result.hpp index c25a2fae..c73e0eed 100644 --- a/boost/asio/async_result.hpp +++ b/boost/asio/async_result.hpp @@ -2,7 +2,7 @@ // async_result.hpp // ~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2023 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) @@ -1321,7 +1321,7 @@ class async_result #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) #endif // !defined(GENERATING_DOCUMENTATION) -#if defined(GENERATION_DOCUMENTATION) +#if defined(GENERATING_DOCUMENTATION) /// The is_async_operation trait detects whether a type @c T and arguments /// @c Args... may be used to initiate an asynchronous operation. @@ -1350,7 +1350,10 @@ struct is_async_operation : template -struct is_async_operation : +struct is_async_operation; + +template +struct is_async_operation : detail::is_async_operation_call< T(detail::async_operation_probe)> { @@ -1399,6 +1402,42 @@ namespace detail { struct completion_signature_probe {}; +#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) + +template +struct completion_signature_probe_result +{ + template