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.
33 // Type utilities needed for implementing typed and type-parameterized
34 // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
36 // Currently we support at most $n types in a list, and at most $n
37 // type-parameterized tests in one type-parameterized test case.
38 // Please contact googletestframework@googlegroups.com if you need
41 // GOOGLETEST_CM0001 DO NOT DELETE
43 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
44 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
46 #include "gtest/internal/gtest-port.h"
48 // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
49 // libstdc++ (which is where cxxabi.h comes from).
50 # if GTEST_HAS_CXXABI_H_
52 # elif defined(__HP_aCC)
53 # include <acxx_demangle.h>
54 # endif // GTEST_HASH_CXXABI_H_
59 // Canonicalizes a given name with respect to the Standard C++ Library.
60 // This handles removing the inline namespace within `std` that is
61 // used by various standard libraries (e.g., `std::__1`). Names outside
62 // of namespace std are returned unmodified.
63 inline std::string CanonicalizeForStdLibVersioning(std::string s) {
64 static const char prefix[] = "std::__";
65 if (s.compare(0, strlen(prefix), prefix) == 0) {
66 std::string::size_type end = s.find("::", strlen(prefix));
68 // Erase everything between the initial `std` and the second `::`.
69 s.erase(strlen("std"), end - strlen("std"));
75 // GetTypeName<T>() returns a human-readable name of type T.
76 // NB: This function is also used in Google Mock, so don't move it inside of
77 // the typed-test-only section below.
79 std::string GetTypeName() {
82 const char* const name = typeid(T).name();
83 # if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
85 // gcc's implementation of typeid(T).name() mangles the type name,
86 // so we have to demangle it.
87 # if GTEST_HAS_CXXABI_H_
88 using abi::__cxa_demangle;
89 # endif // GTEST_HAS_CXXABI_H_
90 char* const readable_name = __cxa_demangle(name, 0, 0, &status);
91 const std::string name_str(status == 0 ? readable_name : name);
93 return CanonicalizeForStdLibVersioning(name_str);
96 # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
102 # endif // GTEST_HAS_RTTI
105 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
107 // AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
108 // type. This can be used as a compile-time assertion to ensure that
109 // two types are equal.
111 template <typename T1, typename T2>
114 template <typename T>
115 struct AssertTypeEq<T, T> {
119 // A unique type used as the default value for the arguments of class
120 // template Types. This allows us to simulate variadic templates
121 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
125 // The following family of struct and struct templates are used to
126 // represent type lists. In particular, TypesN<T1, T2, ..., TN>
127 // represents a type list with N types (T1, T2, ..., and TN) in it.
128 // Except for Types0, every struct in the family has two member types:
129 // Head for the first type in the list, and Tail for the rest of the
132 // The empty type list.
135 // Type lists of length 1, 2, 3, and so on.
137 template <typename T1>
148 template <$for j, [[typename T$j]]>
151 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
157 } // namespace internal
159 // We don't want to require the users to write TypesN<...> directly,
160 // as that would require them to count the length. Types<...> is much
161 // easier to write, but generates horrible messages when there is a
162 // compiler error, as gcc insists on printing out each template
163 // argument, even if it has the default value (this means Types<int>
164 // will appear as Types<int, None, None, ..., None> in the compiler
167 // Our solution is to combine the best part of the two approaches: a
168 // user would write Types<T1, ..., TN>, and Google Test will translate
169 // that to TypesN<T1, ..., TN> internally to make error messages
170 // readable. The translation is done by the 'type' member of the
174 template <$for i, [[typename T$i = internal::None]]>
176 typedef internal::Types$n<$for i, [[T$i]]> type;
180 struct Types<$for i, [[internal::None]]> {
181 typedef internal::Types0 type;
188 template <$for j, [[typename T$j]]>
189 struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
190 typedef internal::Types$i<$for j, [[T$j]]> type;
197 # define GTEST_TEMPLATE_ template <typename T> class
199 // The template "selector" struct TemplateSel<Tmpl> is used to
200 // represent Tmpl, which must be a class template with one type
201 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
202 // as the type Tmpl<T>. This allows us to actually instantiate the
203 // template "selected" by TemplateSel<Tmpl>.
205 // This trick is necessary for simulating typedef for class templates,
206 // which C++ doesn't support directly.
207 template <GTEST_TEMPLATE_ Tmpl>
209 template <typename T>
211 typedef Tmpl<T> type;
215 # define GTEST_BIND_(TmplSel, T) \
216 TmplSel::template Bind<T>::type
218 // A unique struct template used as the default value for the
219 // arguments of class template Templates. This allows us to simulate
220 // variadic templates (e.g. Templates<int>, Templates<int, double>,
221 // and etc), which C++ doesn't support directly.
222 template <typename T>
225 // The following family of struct and struct templates are used to
226 // represent template lists. In particular, TemplatesN<T1, T2, ...,
227 // TN> represents a list of N templates (T1, T2, ..., and TN). Except
228 // for Templates0, every struct in the family has two member types:
229 // Head for the selector of the first template in the list, and Tail
230 // for the rest of the list.
232 // The empty template list.
233 struct Templates0 {};
235 // Template lists of length 1, 2, 3, and so on.
237 template <GTEST_TEMPLATE_ T1>
239 typedef TemplateSel<T1> Head;
240 typedef Templates0 Tail;
248 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
250 typedef TemplateSel<T1> Head;
251 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
257 // We don't want to require the users to write TemplatesN<...> directly,
258 // as that would require them to count the length. Templates<...> is much
259 // easier to write, but generates horrible messages when there is a
260 // compiler error, as gcc insists on printing out each template
261 // argument, even if it has the default value (this means Templates<list>
262 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
265 // Our solution is to combine the best part of the two approaches: a
266 // user would write Templates<T1, ..., TN>, and Google Test will translate
267 // that to TemplatesN<T1, ..., TN> internally to make error messages
268 // readable. The translation is done by the 'type' member of the
269 // Templates template.
272 template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
274 typedef Templates$n<$for i, [[T$i]]> type;
278 struct Templates<$for i, [[NoneT]]> {
279 typedef Templates0 type;
286 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
287 struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
288 typedef Templates$i<$for j, [[T$j]]> type;
293 // The TypeList template makes it possible to use either a single type
294 // or a Types<...> list in TYPED_TEST_CASE() and
295 // INSTANTIATE_TYPED_TEST_CASE_P().
297 template <typename T>
299 typedef Types1<T> type;
304 template <$for i, [[typename T$i]]>
305 struct TypeList<Types<$for i, [[T$i]]> > {
306 typedef typename Types<$for i, [[T$i]]>::type type;
309 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
311 } // namespace internal
312 } // namespace testing
314 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_