Consolidate get_lowest_layer in type_traits.hpp

fix #347
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:16 -07:00
parent 4edd797611
commit f097f401cb
10 changed files with 105 additions and 113 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
#include <beast/core/error.hpp>
#include <beast/core/stream_concepts.hpp>
#include <beast/core/multi_buffer.hpp>
#include <beast/core/detail/get_lowest_layer.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp>
#include <cstdint>
@@ -13,39 +13,6 @@
namespace beast {
namespace detail {
template<class T>
class has_lowest_layer
{
template<class U, class R =
typename U::lowest_layer_type>
static std::true_type check(int);
template<class>
static std::false_type check(...);
using type = decltype(check<T>(0));
public:
static bool constexpr value = type::value;
};
template<class T, bool B>
struct maybe_get_lowest_layer
{
using type = T;
};
template<class T>
struct maybe_get_lowest_layer<T, true>
{
using type = typename T::lowest_layer_type;
};
// If T has a nested type lowest_layer_type,
// returns that, else returns T.
template<class T>
struct get_lowest_layer
{
using type = typename maybe_get_lowest_layer<T,
has_lowest_layer<T>::value>::type;
};
} // detail
} // beast
+33
View File
@@ -127,6 +127,39 @@ struct is_invocable<C, R(A...)>
};
/** @} */
template<class T>
class has_lowest_layer
{
template<class U, class R =
typename U::lowest_layer_type>
static std::true_type check(int);
template<class>
static std::false_type check(...);
using type = decltype(check<T>(0));
public:
static bool constexpr value = type::value;
};
template<class T, bool B>
struct maybe_get_lowest_layer
{
using type = T;
};
template<class T>
struct maybe_get_lowest_layer<T, true>
{
using type = typename T::lowest_layer_type;
};
// Returns T::lowest_layer_type if it exists, else T
template<class T>
struct get_lowest_layer
{
using type = typename maybe_get_lowest_layer<T,
has_lowest_layer<T>::value>::type;
};
} // detail
} // beast
+1 -1
View File
@@ -17,7 +17,7 @@
#include <beast/core/async_result.hpp>
#include <beast/core/buffered_read_stream.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/get_lowest_layer.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <boost/asio.hpp>
#include <algorithm>
#include <cstdint>