]> git.proxmox.com Git - ceph.git/blame - ceph/src/s3select/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h.pump
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / s3select / rapidjson / thirdparty / gtest / googletest / include / gtest / internal / gtest-type-util.h.pump
CommitLineData
31f18b77
FG
1$$ -*- mode: c++; -*-
2$var n = 50 $$ Maximum length of type lists we want to support.
3// Copyright 2008 Google Inc.
4// All Rights Reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//
32// Author: wan@google.com (Zhanyong Wan)
33
34// Type utilities needed for implementing typed and type-parameterized
35// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
36//
37// Currently we support at most $n types in a list, and at most $n
38// type-parameterized tests in one type-parameterized test case.
39// Please contact googletestframework@googlegroups.com if you need
40// more.
41
42#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
43#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
44
45#include "gtest/internal/gtest-port.h"
46
47// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
48// libstdc++ (which is where cxxabi.h comes from).
49# if GTEST_HAS_CXXABI_H_
50# include <cxxabi.h>
51# elif defined(__HP_aCC)
52# include <acxx_demangle.h>
53# endif // GTEST_HASH_CXXABI_H_
54
55namespace testing {
56namespace internal {
57
1e59de90
TL
58// Canonicalizes a given name with respect to the Standard C++ Library.
59// This handles removing the inline namespace within `std` that is
60// used by various standard libraries (e.g., `std::__1`). Names outside
61// of namespace std are returned unmodified.
62inline std::string CanonicalizeForStdLibVersioning(std::string s) {
63 static const char prefix[] = "std::__";
64 if (s.compare(0, strlen(prefix), prefix) == 0) {
65 std::string::size_type end = s.find("::", strlen(prefix));
66 if (end != s.npos) {
67 // Erase everything between the initial `std` and the second `::`.
68 s.erase(strlen("std"), end - strlen("std"));
69 }
70 }
71 return s;
72}
73
31f18b77
FG
74// GetTypeName<T>() returns a human-readable name of type T.
75// NB: This function is also used in Google Mock, so don't move it inside of
76// the typed-test-only section below.
77template <typename T>
78std::string GetTypeName() {
79# if GTEST_HAS_RTTI
80
81 const char* const name = typeid(T).name();
82# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
83 int status = 0;
84 // gcc's implementation of typeid(T).name() mangles the type name,
85 // so we have to demangle it.
86# if GTEST_HAS_CXXABI_H_
87 using abi::__cxa_demangle;
88# endif // GTEST_HAS_CXXABI_H_
89 char* const readable_name = __cxa_demangle(name, 0, 0, &status);
90 const std::string name_str(status == 0 ? readable_name : name);
91 free(readable_name);
1e59de90 92 return CanonicalizeForStdLibVersioning(name_str);
31f18b77
FG
93# else
94 return name;
95# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
96
97# else
98
99 return "<type>";
100
101# endif // GTEST_HAS_RTTI
102}
103
104#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
105
106// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
107// type. This can be used as a compile-time assertion to ensure that
108// two types are equal.
109
110template <typename T1, typename T2>
111struct AssertTypeEq;
112
113template <typename T>
114struct AssertTypeEq<T, T> {
115 typedef bool type;
116};
117
118// A unique type used as the default value for the arguments of class
119// template Types. This allows us to simulate variadic templates
120// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
121// support directly.
122struct None {};
123
124// The following family of struct and struct templates are used to
125// represent type lists. In particular, TypesN<T1, T2, ..., TN>
126// represents a type list with N types (T1, T2, ..., and TN) in it.
127// Except for Types0, every struct in the family has two member types:
128// Head for the first type in the list, and Tail for the rest of the
129// list.
130
131// The empty type list.
132struct Types0 {};
133
134// Type lists of length 1, 2, 3, and so on.
135
136template <typename T1>
137struct Types1 {
138 typedef T1 Head;
139 typedef Types0 Tail;
140};
141
142$range i 2..n
143
144$for i [[
145$range j 1..i
146$range k 2..i
147template <$for j, [[typename T$j]]>
148struct Types$i {
149 typedef T1 Head;
150 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
151};
152
153
154]]
155
156} // namespace internal
157
158// We don't want to require the users to write TypesN<...> directly,
159// as that would require them to count the length. Types<...> is much
160// easier to write, but generates horrible messages when there is a
161// compiler error, as gcc insists on printing out each template
162// argument, even if it has the default value (this means Types<int>
163// will appear as Types<int, None, None, ..., None> in the compiler
164// errors).
165//
166// Our solution is to combine the best part of the two approaches: a
167// user would write Types<T1, ..., TN>, and Google Test will translate
168// that to TypesN<T1, ..., TN> internally to make error messages
169// readable. The translation is done by the 'type' member of the
170// Types template.
171
172$range i 1..n
173template <$for i, [[typename T$i = internal::None]]>
174struct Types {
175 typedef internal::Types$n<$for i, [[T$i]]> type;
176};
177
178template <>
179struct Types<$for i, [[internal::None]]> {
180 typedef internal::Types0 type;
181};
182
183$range i 1..n-1
184$for i [[
185$range j 1..i
186$range k i+1..n
187template <$for j, [[typename T$j]]>
188struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
189 typedef internal::Types$i<$for j, [[T$j]]> type;
190};
191
192]]
193
194namespace internal {
195
196# define GTEST_TEMPLATE_ template <typename T> class
197
198// The template "selector" struct TemplateSel<Tmpl> is used to
199// represent Tmpl, which must be a class template with one type
200// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
201// as the type Tmpl<T>. This allows us to actually instantiate the
202// template "selected" by TemplateSel<Tmpl>.
203//
204// This trick is necessary for simulating typedef for class templates,
205// which C++ doesn't support directly.
206template <GTEST_TEMPLATE_ Tmpl>
207struct TemplateSel {
208 template <typename T>
209 struct Bind {
210 typedef Tmpl<T> type;
211 };
212};
213
214# define GTEST_BIND_(TmplSel, T) \
215 TmplSel::template Bind<T>::type
216
217// A unique struct template used as the default value for the
218// arguments of class template Templates. This allows us to simulate
219// variadic templates (e.g. Templates<int>, Templates<int, double>,
220// and etc), which C++ doesn't support directly.
221template <typename T>
222struct NoneT {};
223
224// The following family of struct and struct templates are used to
225// represent template lists. In particular, TemplatesN<T1, T2, ...,
226// TN> represents a list of N templates (T1, T2, ..., and TN). Except
227// for Templates0, every struct in the family has two member types:
228// Head for the selector of the first template in the list, and Tail
229// for the rest of the list.
230
231// The empty template list.
232struct Templates0 {};
233
234// Template lists of length 1, 2, 3, and so on.
235
236template <GTEST_TEMPLATE_ T1>
237struct Templates1 {
238 typedef TemplateSel<T1> Head;
239 typedef Templates0 Tail;
240};
241
242$range i 2..n
243
244$for i [[
245$range j 1..i
246$range k 2..i
247template <$for j, [[GTEST_TEMPLATE_ T$j]]>
248struct Templates$i {
249 typedef TemplateSel<T1> Head;
250 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
251};
252
253
254]]
255
256// We don't want to require the users to write TemplatesN<...> directly,
257// as that would require them to count the length. Templates<...> is much
258// easier to write, but generates horrible messages when there is a
259// compiler error, as gcc insists on printing out each template
260// argument, even if it has the default value (this means Templates<list>
261// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
262// errors).
263//
264// Our solution is to combine the best part of the two approaches: a
265// user would write Templates<T1, ..., TN>, and Google Test will translate
266// that to TemplatesN<T1, ..., TN> internally to make error messages
267// readable. The translation is done by the 'type' member of the
268// Templates template.
269
270$range i 1..n
271template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
272struct Templates {
273 typedef Templates$n<$for i, [[T$i]]> type;
274};
275
276template <>
277struct Templates<$for i, [[NoneT]]> {
278 typedef Templates0 type;
279};
280
281$range i 1..n-1
282$for i [[
283$range j 1..i
284$range k i+1..n
285template <$for j, [[GTEST_TEMPLATE_ T$j]]>
286struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
287 typedef Templates$i<$for j, [[T$j]]> type;
288};
289
290]]
291
292// The TypeList template makes it possible to use either a single type
293// or a Types<...> list in TYPED_TEST_CASE() and
294// INSTANTIATE_TYPED_TEST_CASE_P().
295
296template <typename T>
297struct TypeList {
298 typedef Types1<T> type;
299};
300
301
302$range i 1..n
303template <$for i, [[typename T$i]]>
304struct TypeList<Types<$for i, [[T$i]]> > {
305 typedef typename Types<$for i, [[T$i]]>::type type;
306};
307
308#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
309
310} // namespace internal
311} // namespace testing
312
313#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_