diff --git a/CHANGELOG.md b/CHANGELOG.md index ba4f479b..a12b0719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/include/boost/beast/core/detail/type_traits.hpp b/include/boost/beast/core/detail/type_traits.hpp index 06fbda29..07feda57 100644 --- a/include/boost/beast/core/detail/type_traits.hpp +++ b/include/boost/beast/core/detail/type_traits.hpp @@ -22,25 +22,8 @@ namespace boost { namespace beast { namespace detail { -// -// utilities -// - -template -struct make_void -{ - using type = void; -}; - -template -using void_t = typename make_void::type; - -template -inline -void -accept_rv(T){} - template +inline std::size_t constexpr max_sizeof() { @@ -48,6 +31,7 @@ max_sizeof() } template +inline std::size_t constexpr max_sizeof() { @@ -57,6 +41,7 @@ max_sizeof() } template +inline std::size_t constexpr max_alignof() { @@ -72,6 +57,36 @@ max_alignof() max_alignof() : max_alignof(); } +// (since C++17) +template struct make_void { using type = void; }; +template using void_t = typename make_void::type; + +// (since C++11) missing from g++4.8 +template +struct aligned_union +{ + static + std::size_t constexpr alignment_value = + max_alignof(); + + using type = typename std::aligned_storage< + (Len > max_sizeof()) ? Len : (max_sizeof()), + alignment_value>::type; +}; + +template +using aligned_union_t = + typename aligned_union::type; + +//------------------------------------------------------------------------------ + +template +inline +void +accept_rv(T){} + +//------------------------------------------------------------------------------ + template struct repeat_tuple_impl { @@ -98,6 +113,8 @@ struct repeat_tuple<0, T> using type = std::tuple<>; }; +//------------------------------------------------------------------------------ + template auto is_invocable_test(C&& c, int, A&& ...a) @@ -132,6 +149,8 @@ struct is_invocable }; /** @} */ +//------------------------------------------------------------------------------ + // for span template struct is_contiguous_container: std::false_type {}; @@ -154,6 +173,8 @@ struct is_contiguous_container::type>>: std::true_type {}; +//------------------------------------------------------------------------------ + template struct unwidest_unsigned; diff --git a/include/boost/beast/core/detail/variant.hpp b/include/boost/beast/core/detail/variant.hpp index cba6ba63..064ebf1c 100644 --- a/include/boost/beast/core/detail/variant.hpp +++ b/include/boost/beast/core/detail/variant.hpp @@ -31,10 +31,7 @@ namespace detail { template class variant { - typename std::aligned_storage< - max_sizeof(), - max_alignof() - >::type buf_; + detail::aligned_union_t<1, TN...> buf_; unsigned char i_ = 0; template