]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/api/include/opentelemetry/nostd/utility.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / api / include / opentelemetry / nostd / utility.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5
6 #ifdef HAVE_CPP_STDLIB
7 # include "opentelemetry/std/utility.h"
8 #else
9
10 # include <cstddef>
11 # include <initializer_list>
12 # include <type_traits>
13
14 # include "opentelemetry/nostd/detail/decay.h"
15 # include "opentelemetry/nostd/detail/invoke.h"
16 # include "opentelemetry/version.h"
17
18 OPENTELEMETRY_BEGIN_NAMESPACE
19 namespace nostd
20 {
21 /**
22 * Back port of std::data
23 *
24 * See https://en.cppreference.com/w/cpp/iterator/data
25 */
26 template <class C>
27 auto data(C &c) noexcept(noexcept(c.data())) -> decltype(c.data())
28 {
29 return c.data();
30 }
31
32 template <class C>
33 auto data(const C &c) noexcept(noexcept(c.data())) -> decltype(c.data())
34 {
35 return c.data();
36 }
37
38 template <class T, size_t N>
39 T *data(T (&array)[N]) noexcept
40 {
41 return array;
42 }
43
44 template <class E>
45 const E *data(std::initializer_list<E> list) noexcept
46 {
47 return list.begin();
48 }
49
50 /**
51 * Back port of std::size
52 *
53 * See https://en.cppreference.com/w/cpp/iterator/size
54 */
55 template <class C>
56 auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
57 {
58 return c.size();
59 }
60
61 template <class T, size_t N>
62 size_t size(T (&array)[N]) noexcept
63 {
64 return N;
65 }
66
67 /**
68 * Back port of std::bool_constant
69 */
70 template <bool B>
71 using bool_constant = std::integral_constant<bool, B>;
72
73 /**
74 * Back port of std::integer_sequence
75 */
76 template <typename T, T... Is>
77 struct integer_sequence
78 {
79 using value_type = T;
80 static constexpr std::size_t size() noexcept { return sizeof...(Is); }
81 };
82
83 /**
84 * Back port of std::index_sequence
85 */
86 template <std::size_t... Is>
87 using index_sequence = integer_sequence<std::size_t, Is...>;
88
89 /**
90 * Back port of std::make_index_sequence
91 */
92 namespace detail
93 {
94 template <class, size_t>
95 struct index_sequence_push_back
96 {};
97
98 template <size_t... Indexes, size_t I>
99 struct index_sequence_push_back<index_sequence<Indexes...>, I>
100 {
101 using type = index_sequence<Indexes..., I>;
102 };
103
104 template <class T, size_t I>
105 using index_sequence_push_back_t = typename index_sequence_push_back<T, I>::type;
106
107 template <size_t N>
108 struct make_index_sequence_impl
109 {
110 using type = index_sequence_push_back_t<typename make_index_sequence_impl<N - 1>::type, N - 1>;
111 };
112
113 template <>
114 struct make_index_sequence_impl<0>
115 {
116 using type = index_sequence<>;
117 };
118 } // namespace detail
119
120 template <size_t N>
121 using make_index_sequence = typename detail::make_index_sequence_impl<N>::type;
122
123 /**
124 * Back port of std::index_sequence_for
125 */
126 template <class... Ts>
127 using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
128
129 /**
130 * Back port of std::in_place_t
131 */
132 struct in_place_t
133 {
134 explicit in_place_t() = default;
135 };
136
137 /**
138 * Back port of std::in_place_index_t
139 */
140 template <std::size_t I>
141 struct in_place_index_t
142 {
143 explicit in_place_index_t() = default;
144 };
145
146 /**
147 * Back port of std::in_place_type_t
148 */
149 template <typename T>
150 struct in_place_type_t
151 {
152 explicit in_place_type_t() = default;
153 };
154 } // namespace nostd
155 OPENTELEMETRY_END_NAMESPACE
156 #endif