2
$var n = 50 $$ Maximum length of type lists we want to support.
3
// Copyright 2008 Google Inc.
4
// All Rights Reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
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
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.
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.
32
// Author: wan@google.com (Zhanyong Wan)
34
// Type utilities needed for implementing typed and type-parameterized
35
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
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
42
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
43
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
45
#include "gtest/internal/gtest-port.h"
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_
51
# elif defined(__HP_aCC)
52
# include <acxx_demangle.h>
53
# endif // GTEST_HASH_CXXABI_H_
58
// GetTypeName<T>() returns a human-readable name of type T.
59
// NB: This function is also used in Google Mock, so don't move it inside of
60
// the typed-test-only section below.
62
std::string GetTypeName() {
65
const char* const name = typeid(T).name();
66
# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
68
// gcc's implementation of typeid(T).name() mangles the type name,
69
// so we have to demangle it.
70
# if GTEST_HAS_CXXABI_H_
71
using abi::__cxa_demangle;
72
# endif // GTEST_HAS_CXXABI_H_
73
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
74
const std::string name_str(status == 0 ? readable_name : name);
79
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
85
# endif // GTEST_HAS_RTTI
88
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
90
// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
91
// type. This can be used as a compile-time assertion to ensure that
92
// two types are equal.
94
template <typename T1, typename T2>
98
struct AssertTypeEq<T, T> {
102
// A unique type used as the default value for the arguments of class
103
// template Types. This allows us to simulate variadic templates
104
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
108
// The following family of struct and struct templates are used to
109
// represent type lists. In particular, TypesN<T1, T2, ..., TN>
110
// represents a type list with N types (T1, T2, ..., and TN) in it.
111
// Except for Types0, every struct in the family has two member types:
112
// Head for the first type in the list, and Tail for the rest of the
115
// The empty type list.
118
// Type lists of length 1, 2, 3, and so on.
120
template <typename T1>
131
template <$for j, [[typename T$j]]>
134
typedef Types$(i-1)<$for k, [[T$k]]> Tail;
140
} // namespace internal
142
// We don't want to require the users to write TypesN<...> directly,
143
// as that would require them to count the length. Types<...> is much
144
// easier to write, but generates horrible messages when there is a
145
// compiler error, as gcc insists on printing out each template
146
// argument, even if it has the default value (this means Types<int>
147
// will appear as Types<int, None, None, ..., None> in the compiler
150
// Our solution is to combine the best part of the two approaches: a
151
// user would write Types<T1, ..., TN>, and Google Test will translate
152
// that to TypesN<T1, ..., TN> internally to make error messages
153
// readable. The translation is done by the 'type' member of the
157
template <$for i, [[typename T$i = internal::None]]>
159
typedef internal::Types$n<$for i, [[T$i]]> type;
163
struct Types<$for i, [[internal::None]]> {
164
typedef internal::Types0 type;
171
template <$for j, [[typename T$j]]>
172
struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
173
typedef internal::Types$i<$for j, [[T$j]]> type;
180
# define GTEST_TEMPLATE_ template <typename T> class
182
// The template "selector" struct TemplateSel<Tmpl> is used to
183
// represent Tmpl, which must be a class template with one type
184
// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
185
// as the type Tmpl<T>. This allows us to actually instantiate the
186
// template "selected" by TemplateSel<Tmpl>.
188
// This trick is necessary for simulating typedef for class templates,
189
// which C++ doesn't support directly.
190
template <GTEST_TEMPLATE_ Tmpl>
192
template <typename T>
194
typedef Tmpl<T> type;
198
# define GTEST_BIND_(TmplSel, T) \
199
TmplSel::template Bind<T>::type
201
// A unique struct template used as the default value for the
202
// arguments of class template Templates. This allows us to simulate
203
// variadic templates (e.g. Templates<int>, Templates<int, double>,
204
// and etc), which C++ doesn't support directly.
205
template <typename T>
208
// The following family of struct and struct templates are used to
209
// represent template lists. In particular, TemplatesN<T1, T2, ...,
210
// TN> represents a list of N templates (T1, T2, ..., and TN). Except
211
// for Templates0, every struct in the family has two member types:
212
// Head for the selector of the first template in the list, and Tail
213
// for the rest of the list.
215
// The empty template list.
216
struct Templates0 {};
218
// Template lists of length 1, 2, 3, and so on.
220
template <GTEST_TEMPLATE_ T1>
222
typedef TemplateSel<T1> Head;
223
typedef Templates0 Tail;
231
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
233
typedef TemplateSel<T1> Head;
234
typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
240
// We don't want to require the users to write TemplatesN<...> directly,
241
// as that would require them to count the length. Templates<...> is much
242
// easier to write, but generates horrible messages when there is a
243
// compiler error, as gcc insists on printing out each template
244
// argument, even if it has the default value (this means Templates<list>
245
// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
248
// Our solution is to combine the best part of the two approaches: a
249
// user would write Templates<T1, ..., TN>, and Google Test will translate
250
// that to TemplatesN<T1, ..., TN> internally to make error messages
251
// readable. The translation is done by the 'type' member of the
252
// Templates template.
255
template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
257
typedef Templates$n<$for i, [[T$i]]> type;
261
struct Templates<$for i, [[NoneT]]> {
262
typedef Templates0 type;
269
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
270
struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
271
typedef Templates$i<$for j, [[T$j]]> type;
276
// The TypeList template makes it possible to use either a single type
277
// or a Types<...> list in TYPED_TEST_CASE() and
278
// INSTANTIATE_TYPED_TEST_CASE_P().
280
template <typename T>
282
typedef Types1<T> type;
287
template <$for i, [[typename T$i]]>
288
struct TypeList<Types<$for i, [[T$i]]> > {
289
typedef typename Types<$for i, [[T$i]]>::type type;
292
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
294
} // namespace internal
295
} // namespace testing
297
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_