diff --git a/CHANGELOG.md b/CHANGELOG.md index 407b8b98..81ecab2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 44 * Use BOOST_THROW_EXCEPTION * Tidy up read_size_helper and dynamic buffers * Require Boost 1.58.0 or later +* Tidy up and make get_lowest_layer public -------------------------------------------------------------------------------- diff --git a/doc/core.qbk b/doc/core.qbk index 0088aaca..c736eae6 100644 --- a/doc/core.qbk +++ b/doc/core.qbk @@ -38,6 +38,11 @@ diagnostics. [table Type Traits [[Name][Description]] +[[ + [link beast.ref.get_lowest_layer `get_lowest_layer`] +][ + Returns `T::lowest_layer_type` if it exists, else returns `T`. +]] [[ [link beast.ref.has_get_io_service `has_get_io_service`] ][ diff --git a/doc/overview.qbk b/doc/overview.qbk index 5afc49e3..9464fd2d 100644 --- a/doc/overview.qbk +++ b/doc/overview.qbk @@ -139,6 +139,7 @@ Asio library and the ideas upon which Beast is built. Beast would not be possible without the considerable time and patience contributed by David Schwartz, Edward Hennis, Howard Hinnant, Miguel Portilla, Nikolaos Bougalis, Scott Determan, Scott Schurr, and Ripple Labs for -supporting its early development. +supporting its early development. Also thanks to Agustín Bergé, Glen Fernandes +and Peter Dimov for putting up with my endless C++ questions on Slack. [endsect] diff --git a/doc/quickref.xml b/doc/quickref.xml index 42765b4e..487761c4 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -194,6 +194,7 @@ Type Traits + get_lowest_layer has_get_io_service is_async_read_stream is_async_write_stream diff --git a/extras/beast/test/fail_stream.hpp b/extras/beast/test/fail_stream.hpp index 33e431e9..c4b38538 100644 --- a/extras/beast/test/fail_stream.hpp +++ b/extras/beast/test/fail_stream.hpp @@ -36,8 +36,7 @@ public: typename std::remove_reference::type; using lowest_layer_type = - typename beast::detail::get_lowest_layer< - next_layer_type>::type; + typename get_lowest_layer::type; fail_stream(fail_stream&&) = delete; fail_stream(fail_stream const&) = delete; diff --git a/include/beast/core/buffered_read_stream.hpp b/include/beast/core/buffered_read_stream.hpp index 9957e2df..4a78b2fc 100644 --- a/include/beast/core/buffered_read_stream.hpp +++ b/include/beast/core/buffered_read_stream.hpp @@ -108,12 +108,7 @@ public: /// The type of the lowest layer. using lowest_layer_type = -#if BEAST_DOXYGEN - implementation_defined; -#else - typename detail::get_lowest_layer< - next_layer_type>::type; -#endif + typename get_lowest_layer::type; /** Move constructor. diff --git a/include/beast/core/detail/get_lowest_layer.hpp b/include/beast/core/detail/get_lowest_layer.hpp deleted file mode 100644 index 7dacfb17..00000000 --- a/include/beast/core/detail/get_lowest_layer.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright (c) 2013-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) -// - -#ifndef BEAST_DETAIL_GET_LOWEST_LAYER_HPP -#define BEAST_DETAIL_GET_LOWEST_LAYER_HPP - -#include - -namespace beast { -namespace detail { - - -} // detail -} // beast - -#endif diff --git a/include/beast/core/detail/type_traits.hpp b/include/beast/core/detail/type_traits.hpp index 56473ed4..34f64e00 100644 --- a/include/beast/core/detail/type_traits.hpp +++ b/include/beast/core/detail/type_traits.hpp @@ -122,39 +122,6 @@ struct is_invocable }; /** @} */ -template -class has_lowest_layer -{ - template - static std::true_type check(int); - template - static std::false_type check(...); - using type = decltype(check(0)); -public: - static bool constexpr value = type::value; -}; - -template -struct maybe_get_lowest_layer -{ - using type = T; -}; - -template -struct maybe_get_lowest_layer -{ - using type = typename T::lowest_layer_type; -}; - -// Returns T::lowest_layer_type if it exists, else T -template -struct get_lowest_layer -{ - using type = typename maybe_get_lowest_layer::value>::type; -}; - //------------------------------------------------------------------------------ // diff --git a/include/beast/core/type_traits.hpp b/include/beast/core/type_traits.hpp index 005934ce..d41230bd 100644 --- a/include/beast/core/type_traits.hpp +++ b/include/beast/core/type_traits.hpp @@ -15,6 +15,12 @@ namespace beast { +//------------------------------------------------------------------------------ +// +// Buffer concepts +// +//------------------------------------------------------------------------------ + /// Determine if `T` meets the requirements of @b ConstBufferSequence. template #if BEAST_DOXYGEN @@ -50,6 +56,29 @@ struct is_mutable_buffer_sequence : { }; +//------------------------------------------------------------------------------ +// +// Handler concepts +// +//------------------------------------------------------------------------------ + +/// Determine if `T` meets the requirements of @b CompletionHandler. +template +#if BEAST_DOXYGEN +using is_completion_handler = std::integral_constant; +#else +using is_completion_handler = std::integral_constant::type>::value && + detail::is_invocable::value>; +#endif + + +//------------------------------------------------------------------------------ +// +// Stream concepts +// +//------------------------------------------------------------------------------ + /// Determine if `T` has the `get_io_service` member. template #if BEAST_DOXYGEN @@ -58,6 +87,25 @@ struct has_get_io_service : std::integral_constant{}; using has_get_io_service = typename detail::has_get_io_service::type; #endif +/// Returns `T::lowest_layer_type` if it exists, else `T` +#if BEAST_DOXYGEN +template +struct get_lowest_layer; +#else +template +struct get_lowest_layer +{ + using type = T; +}; + +template +struct get_lowest_layer> +{ + using type = typename T::lowest_layer_type; +}; +#endif + /// Determine if `T` meets the requirements of @b AsyncReadStream. template #if BEAST_DOXYGEN @@ -108,16 +156,6 @@ using is_sync_stream = std::integral_constant::value && is_sync_write_stream::value>; #endif -/// Determine if `T` meets the requirements of @b CompletionHandler. -template -#if BEAST_DOXYGEN -using is_completion_handler = std::integral_constant; -#else -using is_completion_handler = std::integral_constant::type>::value && - detail::is_invocable::value>; -#endif - } // beast #endif diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 0ac02bbb..e575357e 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -107,12 +107,7 @@ public: /// The type of the lowest layer. using lowest_layer_type = - #if BEAST_DOXYGEN - implementation_defined; - #else - typename beast::detail::get_lowest_layer< - next_layer_type>::type; - #endif + typename get_lowest_layer::type; /** Move-construct a stream. diff --git a/test/core/type_traits.cpp b/test/core/type_traits.cpp index c439ff65..063d135e 100644 --- a/test/core/type_traits.cpp +++ b/test/core/type_traits.cpp @@ -86,11 +86,6 @@ struct F4 get_lowest_layer::type; }; -static_assert(! has_lowest_layer::value, ""); -static_assert(! has_lowest_layer::value, ""); -static_assert(has_lowest_layer>::value, ""); -static_assert(has_lowest_layer>>::value, ""); - static_assert(std::is_same< get_lowest_layer::type, F1>::value, "");