Add detail::aligned_union and tidy up

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2017-11-26 00:47:58 +01:00
committed by Vinnie Falco
parent fb0d82245f
commit 332c2fe0cb
3 changed files with 41 additions and 22 deletions

View File

@ -4,6 +4,7 @@ Version 146:
* Faster ascii_tolower
* Documentation tidying
* Fix typo in examples documentation
* Add detail::aligned_union and tidy up
API Changes:

View File

@ -22,25 +22,8 @@ namespace boost {
namespace beast {
namespace detail {
//
// utilities
//
template<class... Ts>
struct make_void
{
using type = void;
};
template<class... Ts>
using void_t = typename make_void<Ts...>::type;
template<class T>
inline
void
accept_rv(T){}
template<class U>
inline
std::size_t constexpr
max_sizeof()
{
@ -48,6 +31,7 @@ max_sizeof()
}
template<class U0, class U1, class... Us>
inline
std::size_t constexpr
max_sizeof()
{
@ -57,6 +41,7 @@ max_sizeof()
}
template<class U>
inline
std::size_t constexpr
max_alignof()
{
@ -72,6 +57,36 @@ max_alignof()
max_alignof<U0>() : max_alignof<U1, Us...>();
}
// (since C++17)
template<class... Ts> struct make_void { using type = void; };
template<class... Ts> using void_t = typename make_void<Ts...>::type;
// (since C++11) missing from g++4.8
template<std::size_t Len, class... Ts>
struct aligned_union
{
static
std::size_t constexpr alignment_value =
max_alignof<Ts...>();
using type = typename std::aligned_storage<
(Len > max_sizeof<Ts...>()) ? Len : (max_sizeof<Ts...>()),
alignment_value>::type;
};
template<std::size_t Len, class... Ts>
using aligned_union_t =
typename aligned_union<Len, Ts...>::type;
//------------------------------------------------------------------------------
template<class T>
inline
void
accept_rv(T){}
//------------------------------------------------------------------------------
template<unsigned N, class T, class... Tn>
struct repeat_tuple_impl
{
@ -98,6 +113,8 @@ struct repeat_tuple<0, T>
using type = std::tuple<>;
};
//------------------------------------------------------------------------------
template<class R, class C, class ...A>
auto
is_invocable_test(C&& c, int, A&& ...a)
@ -132,6 +149,8 @@ struct is_invocable<C, R(A...)>
};
/** @} */
//------------------------------------------------------------------------------
// for span
template<class T, class E, class = void>
struct is_contiguous_container: std::false_type {};
@ -154,6 +173,8 @@ struct is_contiguous_container<T, E, void_t<
>::type>>: std::true_type
{};
//------------------------------------------------------------------------------
template<class...>
struct unwidest_unsigned;

View File

@ -31,10 +31,7 @@ namespace detail {
template<class... TN>
class variant
{
typename std::aligned_storage<
max_sizeof<TN...>(),
max_alignof<TN...>()
>::type buf_;
detail::aligned_union_t<1, TN...> buf_;
unsigned char i_ = 0;
template<std::size_t I>