diff --git a/CHANGELOG.md b/CHANGELOG.md index 326d00d2..182d7a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Version 210: * Fix stable_async_op_base javadoc * Better handling of stream timeouts * Add stream_traits.hpp +* Add executor_type trait -------------------------------------------------------------------------------- diff --git a/doc/qbk/03_core/2_streams.qbk b/doc/qbk/03_core/2_streams.qbk index 2f9e3a20..b208d73f 100644 --- a/doc/qbk/03_core/2_streams.qbk +++ b/doc/qbk/03_core/2_streams.qbk @@ -58,8 +58,13 @@ and also provides them as public interfaces so users may use the same techniques to augment their own code. The use of these type checks helps provide more concise errors during compilation: -[table Stream Type Checks +[table Type Traits and Metafunctions [[Name][Description]] +[[ + [link beast.ref.boost__beast__executor_type `executor_type`] +][ + An alias for the type of object returned by `get_executor`. +]] [[ [link beast.ref.boost__beast__has_get_executor `has_get_executor`] ][ diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml index 98dca9f3..9f2269b6 100644 --- a/doc/qbk/quickref.xml +++ b/doc/qbk/quickref.xml @@ -76,6 +76,7 @@ Type Traits + executor_type 🞲 lowest_layer_type 🞲 has_get_executor is_async_read_stream diff --git a/doc/qbk/release_notes.qbk b/doc/qbk/release_notes.qbk index ffa71d58..865797d7 100644 --- a/doc/qbk/release_notes.qbk +++ b/doc/qbk/release_notes.qbk @@ -40,7 +40,7 @@ New websocket-chat-multi example * Eligible member functions are declared `noexcept` * ([issue 1345]) Better `flat_buffer`, `multi_buffer` - * Add `reserve()`, `max_size()`, `shrink_to_fit()` + * Add `clear`, `reserve()`, `max_size()`, `shrink_to_fit()` * Respect Allocator `max_size()` * Specify exception safety @@ -53,7 +53,7 @@ New websocket-chat-multi example * Faster `http::string_to_field` -* New file +* New file * New variadic `is_const_buffer_sequence` * New variadic `is_mutable_buffer_sequence` * New `buffers_iterator_type` trait @@ -69,6 +69,7 @@ New websocket-chat-multi example * `saved_handler` * `buffers_range_ref` * `dynamic_buffer_ref` + * `executor_type` * `get_lowest_layer` and `lowest_layer_type` * `close_socket` and `beast_close_socket` * `error` and `condition` diff --git a/include/boost/beast/_experimental/core/impl/flat_stream.hpp b/include/boost/beast/_experimental/core/impl/flat_stream.hpp index 8a15a309..93ea5c5a 100644 --- a/include/boost/beast/_experimental/core/impl/flat_stream.hpp +++ b/include/boost/beast/_experimental/core/impl/flat_stream.hpp @@ -10,9 +10,9 @@ #ifndef BOOST_BEAST_CORE_IMPL_FLAT_STREAM_HPP #define BOOST_BEAST_CORE_IMPL_FLAT_STREAM_HPP -#include #include -#include +#include +#include #include #include #include @@ -25,7 +25,7 @@ template template class flat_stream::write_op : public async_op_base> + beast::executor_type> , public net::coroutine { @@ -60,7 +60,7 @@ public: ConstBufferSequence const& b, Handler_&& h) : async_op_base>( + beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) diff --git a/include/boost/beast/_experimental/http/impl/icy_stream.hpp b/include/boost/beast/_experimental/http/impl/icy_stream.hpp index 6b90177f..775a46a0 100644 --- a/include/boost/beast/_experimental/http/impl/icy_stream.hpp +++ b/include/boost/beast/_experimental/http/impl/icy_stream.hpp @@ -10,15 +10,15 @@ #ifndef BOOST_BEAST_CORE_IMPL_ICY_STREAM_HPP #define BOOST_BEAST_CORE_IMPL_ICY_STREAM_HPP -#include #include #include #include #include #include #include +#include +#include #include -#include #include #include #include @@ -121,7 +121,7 @@ template template class icy_stream::read_op : public beast::stable_async_op_base> + beast::executor_type> , public net::coroutine { // VFALCO We need a stable reference to `b` @@ -151,7 +151,7 @@ public: icy_stream& s, MutableBufferSequence const& b) : stable_async_op_base>( + beast::executor_type>( std::forward(h), s.get_executor()) , d_(beast::allocate_stable(*this, s, b)) { diff --git a/include/boost/beast/core/buffered_read_stream.hpp b/include/boost/beast/core/buffered_read_stream.hpp index 69a757f6..293ed920 100644 --- a/include/boost/beast/core/buffered_read_stream.hpp +++ b/include/boost/beast/core/buffered_read_stream.hpp @@ -13,8 +13,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -148,7 +148,7 @@ public: } using executor_type = - detail::get_executor_type; + beast::executor_type; /** Get the executor associated with the object. diff --git a/include/boost/beast/core/detail/get_executor_type.hpp b/include/boost/beast/core/detail/get_executor_type.hpp deleted file mode 100644 index 35d38b53..00000000 --- a/include/boost/beast/core/detail/get_executor_type.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -#ifndef BOOST_BEAST_DETAIL_GET_EXECUTOR_TYPE -#define BOOST_BEAST_DETAIL_GET_EXECUTOR_TYPE - -#include -#include - -namespace boost { -namespace beast { -namespace detail { - -// Workaround for ICE on gcc 4.8 -#if BOOST_WORKAROUND(BOOST_GCC, < 40900) -template -using get_executor_type = - typename std::decay::type::executor_type; -#else -template -using get_executor_type = - decltype(std::declval().get_executor()); -#endif - -} // detail -} // beast -} // boost - -#endif diff --git a/include/boost/beast/core/detail/impl/read.hpp b/include/boost/beast/core/detail/impl/read.hpp index 555d40d7..89b6ed10 100644 --- a/include/boost/beast/core/detail/impl/read.hpp +++ b/include/boost/beast/core/detail/impl/read.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ template< class read_op : public net::coroutine , public async_op_base< - Handler, get_executor_type> + Handler, beast::executor_type> { Stream& s_; DynamicBuffer& b_; @@ -54,7 +54,7 @@ public: Condition cond, Handler_&& h) : async_op_base>( + beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) @@ -115,7 +115,7 @@ template< class read_non_blocking_op : public net::coroutine , public async_op_base>> + beast::executor_type>> { net::basic_stream_socket& s_; DynamicBuffer& b_; @@ -133,7 +133,7 @@ public: DynamicBuffer& b, Condition cond, Handler_&& h) - : async_op_base>>( s.get_executor(), std::forward(h)) , s_(s) diff --git a/include/boost/beast/core/impl/buffered_read_stream.hpp b/include/boost/beast/core/impl/buffered_read_stream.hpp index bc295de6..b512e204 100644 --- a/include/boost/beast/core/impl/buffered_read_stream.hpp +++ b/include/boost/beast/core/impl/buffered_read_stream.hpp @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include #include #include @@ -27,7 +27,7 @@ template class buffered_read_stream< Stream, DynamicBuffer>::read_some_op : public async_op_base< - Handler, detail::get_executor_type> + Handler, beast::executor_type> { buffered_read_stream& s_; MutableBufferSequence b_; @@ -43,7 +43,7 @@ public: buffered_read_stream& s, MutableBufferSequence const& b) : async_op_base< - Handler, detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) , b_(b) diff --git a/include/boost/beast/core/stream_traits.hpp b/include/boost/beast/core/stream_traits.hpp index aaae224f..b6b3e801 100644 --- a/include/boost/beast/core/stream_traits.hpp +++ b/include/boost/beast/core/stream_traits.hpp @@ -16,12 +16,15 @@ namespace boost { namespace beast { -/** Return the type of the lowest layer of a type representing a stack of stream layers. +/** A trait to determine the lowest layer type of a stack of stream layers. - This type alias will return the type of lowest layer object for a type - which defines a stack of stream layers. + If `t.next_layer()` is well-defined for an object `t` of type `T`, + then `lowest_layer_type` will be an alias for + `lowest_layer_type`, + otherwise it will be the type + `std::remove_reference`. - @param T The type determine the lowest layer type of. + @param T The type to determine the lowest layer type of. @return The type of the lowest layer. */ @@ -35,7 +38,7 @@ using lowest_layer_type = detail::lowest_layer_type; /** Return the lowest layer in a stack of stream layers. If `t.next_layer()` is well-defined, returns - `lowest_layer(t.next_layer())`. Otherwise, it returns `t`. + `get_lowest_layer(t.next_layer())`. Otherwise, it returns `t`. A stream layer is an object of class type which wraps another object through composition, and meets some or all of the named requirements of the wrapped @@ -84,6 +87,29 @@ get_lowest_layer(T& t) noexcept t, detail::has_next_layer{}); } +/** A trait to determine the return type of get_executor. + + This type alias will be the type of values returned by + by calling member `get_exector` on an object of type `T&`. + + @param T The type to query + + @return The type of values returned from `get_executor`. +*/ +// Workaround for ICE on gcc 4.8 +#if BOOST_BEAST_DOXYGEN +template +using executor_type = __see_below__; +#elif BOOST_WORKAROUND(BOOST_GCC, < 40900) +template +using executor_type = + typename std::decay::type::executor_type; +#else +template +using executor_type = + decltype(std::declval().get_executor()); +#endif + } // beast } // boost diff --git a/include/boost/beast/http/impl/read.ipp b/include/boost/beast/http/impl/read.ipp index 2204ed6c..c81e0348 100644 --- a/include/boost/beast/http/impl/read.ipp +++ b/include/boost/beast/http/impl/read.ipp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -149,7 +149,7 @@ template< class Handler> class read_msg_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { using parser_type = @@ -184,7 +184,7 @@ public: message_type& m, Handler_&& h) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), s.get_executor()) , d_(beast::allocate_stable( *this, s, m)) diff --git a/include/boost/beast/http/impl/write.ipp b/include/boost/beast/http/impl/write.ipp index 7ab73e9d..4e957f46 100644 --- a/include/boost/beast/http/impl/write.ipp +++ b/include/boost/beast/http/impl/write.ipp @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -35,7 +35,7 @@ template< bool isRequest, class Body, class Fields> class write_some_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> { Stream& s_; serializer& sr_; @@ -73,7 +73,7 @@ public: Stream& s, serializer& sr) : async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) , sr_(sr) @@ -155,7 +155,7 @@ template< bool isRequest, class Body, class Fields> class write_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { Stream& s_; @@ -169,7 +169,7 @@ public: Stream& s, serializer& sr) : async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) , sr_(sr) @@ -216,7 +216,7 @@ template< bool isRequest, class Body, class Fields> class write_msg_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> { Stream& s_; serializer& sr_; @@ -230,7 +230,7 @@ public: Handler_&& h, Args&&... args) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), s.get_executor()) , s_(s) , sr_(beast::allocate_stable< diff --git a/include/boost/beast/websocket/impl/accept.hpp b/include/boost/beast/websocket/impl/accept.hpp index 9eabf5d2..0c123fd6 100644 --- a/include/boost/beast/websocket/impl/accept.hpp +++ b/include/boost/beast/websocket/impl/accept.hpp @@ -19,8 +19,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -39,7 +39,7 @@ template template class stream::response_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { stream& ws_; @@ -57,7 +57,7 @@ public: http::request> const& req, Decorator const& decorator) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , ws_(ws) , res_(beast::allocate_stable(*this, @@ -96,7 +96,7 @@ template template class stream::accept_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { stream& ws_; @@ -110,7 +110,7 @@ public: stream& ws, Decorator const& decorator) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , ws_(ws) , p_(beast::allocate_stable< diff --git a/include/boost/beast/websocket/impl/close.hpp b/include/boost/beast/websocket/impl/close.hpp index e5161cdc..a61ed570 100644 --- a/include/boost/beast/websocket/impl/close.hpp +++ b/include/boost/beast/websocket/impl/close.hpp @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -37,7 +37,7 @@ template template class stream::close_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { struct state @@ -69,7 +69,7 @@ public: stream& ws, close_reason const& cr) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , d_(beast::allocate_stable( *this, ws, cr)) diff --git a/include/boost/beast/websocket/impl/handshake.hpp b/include/boost/beast/websocket/impl/handshake.hpp index 68e74d34..247be2fc 100644 --- a/include/boost/beast/websocket/impl/handshake.hpp +++ b/include/boost/beast/websocket/impl/handshake.hpp @@ -16,8 +16,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -35,7 +35,7 @@ template template class stream::handshake_op : public beast::stable_async_op_base> + beast::executor_type> , public net::coroutine { struct data @@ -72,7 +72,7 @@ public: Handler_&& h, stream& ws, Args&&... args) : stable_async_op_base>( + beast::executor_type>( std::forward(h), ws.get_executor()) , d_(beast::allocate_stable( *this, ws, std::forward(args)...)) diff --git a/include/boost/beast/websocket/impl/ping.hpp b/include/boost/beast/websocket/impl/ping.hpp index 099eee2a..72307991 100644 --- a/include/boost/beast/websocket/impl/ping.hpp +++ b/include/boost/beast/websocket/impl/ping.hpp @@ -12,8 +12,8 @@ #include #include +#include #include -#include #include #include #include @@ -33,7 +33,7 @@ template template class stream::ping_op : public beast::stable_async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { struct state @@ -66,7 +66,7 @@ public: detail::opcode op, ping_data const& payload) : stable_async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , d_(beast::allocate_stable( *this, ws, op, payload)) diff --git a/include/boost/beast/websocket/impl/read.hpp b/include/boost/beast/websocket/impl/read.hpp index c5f55b85..05e019c7 100644 --- a/include/boost/beast/websocket/impl/read.hpp +++ b/include/boost/beast/websocket/impl/read.hpp @@ -18,11 +18,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -47,7 +47,7 @@ template< class Handler> class stream::read_some_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { stream& ws_; @@ -68,7 +68,7 @@ public: stream& ws, MutableBufferSequence const& bs) : async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , ws_(ws) , bs_(bs) @@ -631,7 +631,7 @@ template< class Handler> class stream::read_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { stream& ws_; @@ -649,7 +649,7 @@ public: std::size_t limit, bool some) : async_op_base< - Handler, beast::detail::get_executor_type>( + Handler, beast::executor_type>( std::forward(h), ws.get_executor()) , ws_(ws) , b_(b) diff --git a/include/boost/beast/websocket/impl/teardown.hpp b/include/boost/beast/websocket/impl/teardown.hpp index c01aecd7..eebf9796 100644 --- a/include/boost/beast/websocket/impl/teardown.hpp +++ b/include/boost/beast/websocket/impl/teardown.hpp @@ -12,8 +12,8 @@ #include #include +#include #include -#include #include #include #include @@ -27,7 +27,7 @@ namespace detail { template class teardown_tcp_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type< + Handler, beast::executor_type< net::ip::tcp::socket>> , public net::coroutine { @@ -44,7 +44,7 @@ public: socket_type& s, role_type role) : async_op_base>( std::forward(h), s.get_executor()) , s_(s) diff --git a/include/boost/beast/websocket/impl/write.hpp b/include/boost/beast/websocket/impl/write.hpp index 8c3da28c..d5063992 100644 --- a/include/boost/beast/websocket/impl/write.hpp +++ b/include/boost/beast/websocket/impl/write.hpp @@ -19,10 +19,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -39,7 +39,7 @@ template template class stream::write_some_op : public beast::async_op_base< - Handler, beast::detail::get_executor_type> + Handler, beast::executor_type> , public net::coroutine { stream& ws_; @@ -64,7 +64,7 @@ public: bool fin, Buffers const& bs) : beast::async_op_base>( + beast::executor_type>( std::forward(h), ws.get_executor()) , ws_(ws) , cb_(bs) diff --git a/test/doc/core_3_layers.cpp b/test/doc/core_3_layers.cpp index c1181766..b62c3d33 100644 --- a/test/doc/core_3_layers.cpp +++ b/test/doc/core_3_layers.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,7 +75,7 @@ class counted_stream public: /// The type of executor used by this stream - using executor_type = detail::get_executor_type; + using executor_type = beast::executor_type; /// Constructor template