2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
11 #define BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
13 #include <boost/type_traits/make_void.hpp>
14 #include <type_traits>
28 template<class U0, class U1, class... Us>
33 max_sizeof<U0>() > max_sizeof<U1, Us...>() ?
34 max_sizeof<U0>() : max_sizeof<U1, Us...>();
44 template<class U0, class U1, class... Us>
49 max_alignof<U0>() > max_alignof<U1, Us...>() ?
50 max_alignof<U0>() : max_alignof<U1, Us...>();
55 using make_void = boost::make_void<Ts...>;
57 using void_t = boost::void_t<Ts...>;
59 // (since C++11) missing from g++4.8
60 template<std::size_t Len, class... Ts>
64 std::size_t constexpr alignment_value =
67 using type = typename std::aligned_storage<
68 (Len > max_sizeof<Ts...>()) ? Len : (max_sizeof<Ts...>()),
69 alignment_value>::type;
72 template<std::size_t Len, class... Ts>
73 using aligned_union_t =
74 typename aligned_union<Len, Ts...>::type;
76 //------------------------------------------------------------------------------
79 template<class T, class E, class = void>
80 struct is_contiguous_container: std::false_type {};
82 template<class T, class E>
83 struct is_contiguous_container<T, E, void_t<
85 std::declval<std::size_t&>() = std::declval<T const&>().size(),
86 std::declval<E*&>() = std::declval<T&>().data()),
87 typename std::enable_if<
89 typename std::remove_cv<E>::type,
90 typename std::remove_cv<
91 typename std::remove_pointer<
92 decltype(std::declval<T&>().data())
96 >::type>>: std::true_type
99 template <class T, class U>
102 #if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606
103 return std::launder(reinterpret_cast<T>(u));
104 #elif defined(BOOST_GCC) && BOOST_GCC_VERSION > 80000
105 return __builtin_launder(reinterpret_cast<T>(u));
107 return reinterpret_cast<T>(u);