]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/detail/type_traits.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / beast / core / detail / type_traits.hpp
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
11 #define BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
12
13 #include <boost/type_traits/make_void.hpp>
14 #include <type_traits>
15 #include <new>
16
17 namespace boost {
18 namespace beast {
19 namespace detail {
20
21 template<class U>
22 std::size_t constexpr
23 max_sizeof()
24 {
25 return sizeof(U);
26 }
27
28 template<class U0, class U1, class... Us>
29 std::size_t constexpr
30 max_sizeof()
31 {
32 return
33 max_sizeof<U0>() > max_sizeof<U1, Us...>() ?
34 max_sizeof<U0>() : max_sizeof<U1, Us...>();
35 }
36
37 template<class U>
38 std::size_t constexpr
39 max_alignof()
40 {
41 return alignof(U);
42 }
43
44 template<class U0, class U1, class... Us>
45 std::size_t constexpr
46 max_alignof()
47 {
48 return
49 max_alignof<U0>() > max_alignof<U1, Us...>() ?
50 max_alignof<U0>() : max_alignof<U1, Us...>();
51 }
52
53 // (since C++17)
54 template<class... Ts>
55 using make_void = boost::make_void<Ts...>;
56 template<class... Ts>
57 using void_t = boost::void_t<Ts...>;
58
59 // (since C++11) missing from g++4.8
60 template<std::size_t Len, class... Ts>
61 struct aligned_union
62 {
63 static
64 std::size_t constexpr alignment_value =
65 max_alignof<Ts...>();
66
67 using type = typename std::aligned_storage<
68 (Len > max_sizeof<Ts...>()) ? Len : (max_sizeof<Ts...>()),
69 alignment_value>::type;
70 };
71
72 template<std::size_t Len, class... Ts>
73 using aligned_union_t =
74 typename aligned_union<Len, Ts...>::type;
75
76 //------------------------------------------------------------------------------
77
78 // for span
79 template<class T, class E, class = void>
80 struct is_contiguous_container: std::false_type {};
81
82 template<class T, class E>
83 struct is_contiguous_container<T, E, void_t<
84 decltype(
85 std::declval<std::size_t&>() = std::declval<T const&>().size(),
86 std::declval<E*&>() = std::declval<T&>().data()),
87 typename std::enable_if<
88 std::is_same<
89 typename std::remove_cv<E>::type,
90 typename std::remove_cv<
91 typename std::remove_pointer<
92 decltype(std::declval<T&>().data())
93 >::type
94 >::type
95 >::value
96 >::type>>: std::true_type
97 {};
98
99 template <class T, class U>
100 T launder_cast(U* u)
101 {
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));
106 #else
107 return reinterpret_cast<T>(u);
108 #endif
109 }
110
111 } // detail
112 } // beast
113 } // boost
114
115 #endif