]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/googletest/googletest/include/gtest/internal/gtest-type-util.h
1 // Copyright 2008 Google Inc.
2 // All Rights Reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // Type utilities needed for implementing typed and type-parameterized
33 // GOOGLETEST_CM0001 DO NOT DELETE
35 #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
36 #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
38 #include "gtest/internal/gtest-port.h"
40 // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
41 // libstdc++ (which is where cxxabi.h comes from).
42 # if GTEST_HAS_CXXABI_H_
44 # elif defined(__HP_aCC)
45 # include <acxx_demangle.h>
46 # endif // GTEST_HASH_CXXABI_H_
51 // Canonicalizes a given name with respect to the Standard C++ Library.
52 // This handles removing the inline namespace within `std` that is
53 // used by various standard libraries (e.g., `std::__1`). Names outside
54 // of namespace std are returned unmodified.
55 inline std::string
CanonicalizeForStdLibVersioning(std::string s
) {
56 static const char prefix
[] = "std::__";
57 if (s
.compare(0, strlen(prefix
), prefix
) == 0) {
58 std::string::size_type end
= s
.find("::", strlen(prefix
));
60 // Erase everything between the initial `std` and the second `::`.
61 s
.erase(strlen("std"), end
- strlen("std"));
68 // GetTypeName(const std::type_info&) returns a human-readable name of type T.
69 inline std::string
GetTypeName(const std::type_info
& type
) {
70 const char* const name
= type
.name();
71 #if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
73 // gcc's implementation of typeid(T).name() mangles the type name,
74 // so we have to demangle it.
75 #if GTEST_HAS_CXXABI_H_
76 using abi::__cxa_demangle
;
77 #endif // GTEST_HAS_CXXABI_H_
78 char* const readable_name
= __cxa_demangle(name
, nullptr, nullptr, &status
);
79 const std::string
name_str(status
== 0 ? readable_name
: name
);
81 return CanonicalizeForStdLibVersioning(name_str
);
84 #endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
86 #endif // GTEST_HAS_RTTI
88 // GetTypeName<T>() returns a human-readable name of type T if and only if
89 // RTTI is enabled, otherwise it returns a dummy type name.
90 // NB: This function is also used in Google Mock, so don't move it inside of
91 // the typed-test-only section below.
93 std::string
GetTypeName() {
95 return GetTypeName(typeid(T
));
98 #endif // GTEST_HAS_RTTI
101 // A unique type indicating an empty node
104 # define GTEST_TEMPLATE_ template <typename T> class
106 // The template "selector" struct TemplateSel<Tmpl> is used to
107 // represent Tmpl, which must be a class template with one type
108 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
109 // as the type Tmpl<T>. This allows us to actually instantiate the
110 // template "selected" by TemplateSel<Tmpl>.
112 // This trick is necessary for simulating typedef for class templates,
113 // which C++ doesn't support directly.
114 template <GTEST_TEMPLATE_ Tmpl
>
116 template <typename T
>
118 typedef Tmpl
<T
> type
;
122 # define GTEST_BIND_(TmplSel, T) \
123 TmplSel::template Bind<T>::type
125 template <GTEST_TEMPLATE_ Head_
, GTEST_TEMPLATE_
... Tail_
>
127 using Head
= TemplateSel
<Head_
>;
128 using Tail
= Templates
<Tail_
...>;
131 template <GTEST_TEMPLATE_ Head_
>
132 struct Templates
<Head_
> {
133 using Head
= TemplateSel
<Head_
>;
137 // Tuple-like type lists
138 template <typename Head_
, typename
... Tail_
>
141 using Tail
= Types
<Tail_
...>;
144 template <typename Head_
>
145 struct Types
<Head_
> {
150 // Helper metafunctions to tell apart a single type from types
151 // generated by ::testing::Types
152 template <typename
... Ts
>
153 struct ProxyTypeList
{
154 using type
= Types
<Ts
...>;
158 struct is_proxy_type_list
: std::false_type
{};
160 template <typename
... Ts
>
161 struct is_proxy_type_list
<ProxyTypeList
<Ts
...>> : std::true_type
{};
163 // Generator which conditionally creates type lists.
164 // It recognizes if a requested type list should be created
165 // and prevents creating a new type list nested within another one.
166 template <typename T
>
167 struct GenerateTypeList
{
169 using proxy
= typename
std::conditional
<is_proxy_type_list
<T
>::value
, T
,
170 ProxyTypeList
<T
>>::type
;
173 using type
= typename
proxy::type
;
176 } // namespace internal
178 template <typename
... Ts
>
179 using Types
= internal::ProxyTypeList
<Ts
...>;
181 } // namespace testing
183 #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_