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 suite.
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, nullptr, nullptr, &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 // A unique type used as the default value for the arguments of class
108 // template Types. This allows us to simulate variadic templates
109 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
113 // The following family of struct and struct templates are used to
114 // represent type lists. In particular, TypesN<T1, T2, ..., TN>
115 // represents a type list with N types (T1, T2, ..., and TN) in it.
116 // Except for Types0, every struct in the family has two member types:
117 // Head for the first type in the list, and Tail for the rest of the
120 // The empty type list.
123 // Type lists of length 1, 2, 3, and so on.
125 template <typename T1>
136 template <$for j, [[typename T$j]]>
139 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
145 } // namespace internal
147 // We don't want to require the users to write TypesN<...> directly,
148 // as that would require them to count the length. Types<...> is much
149 // easier to write, but generates horrible messages when there is a
150 // compiler error, as gcc insists on printing out each template
151 // argument, even if it has the default value (this means Types<int>
152 // will appear as Types<int, None, None, ..., None> in the compiler
155 // Our solution is to combine the best part of the two approaches: a
156 // user would write Types<T1, ..., TN>, and Google Test will translate
157 // that to TypesN<T1, ..., TN> internally to make error messages
158 // readable. The translation is done by the 'type' member of the
162 template <$for i, [[typename T$i = internal::None]]>
164 typedef internal::Types$n<$for i, [[T$i]]> type;
168 struct Types<$for i, [[internal::None]]> {
169 typedef internal::Types0 type;
176 template <$for j, [[typename T$j]]>
177 struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
178 typedef internal::Types$i<$for j, [[T$j]]> type;
185 # define GTEST_TEMPLATE_ template <typename T> class
187 // The template "selector" struct TemplateSel<Tmpl> is used to
188 // represent Tmpl, which must be a class template with one type
189 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
190 // as the type Tmpl<T>. This allows us to actually instantiate the
191 // template "selected" by TemplateSel<Tmpl>.
193 // This trick is necessary for simulating typedef for class templates,
194 // which C++ doesn't support directly.
195 template <GTEST_TEMPLATE_ Tmpl>
197 template <typename T>
199 typedef Tmpl<T> type;
203 # define GTEST_BIND_(TmplSel, T) \
204 TmplSel::template Bind<T>::type
206 // A unique struct template used as the default value for the
207 // arguments of class template Templates. This allows us to simulate
208 // variadic templates (e.g. Templates<int>, Templates<int, double>,
209 // and etc), which C++ doesn't support directly.
210 template <typename T>
213 // The following family of struct and struct templates are used to
214 // represent template lists. In particular, TemplatesN<T1, T2, ...,
215 // TN> represents a list of N templates (T1, T2, ..., and TN). Except
216 // for Templates0, every struct in the family has two member types:
217 // Head for the selector of the first template in the list, and Tail
218 // for the rest of the list.
220 // The empty template list.
221 struct Templates0 {};
223 // Template lists of length 1, 2, 3, and so on.
225 template <GTEST_TEMPLATE_ T1>
227 typedef TemplateSel<T1> Head;
228 typedef Templates0 Tail;
236 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
238 typedef TemplateSel<T1> Head;
239 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
245 // We don't want to require the users to write TemplatesN<...> directly,
246 // as that would require them to count the length. Templates<...> is much
247 // easier to write, but generates horrible messages when there is a
248 // compiler error, as gcc insists on printing out each template
249 // argument, even if it has the default value (this means Templates<list>
250 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
253 // Our solution is to combine the best part of the two approaches: a
254 // user would write Templates<T1, ..., TN>, and Google Test will translate
255 // that to TemplatesN<T1, ..., TN> internally to make error messages
256 // readable. The translation is done by the 'type' member of the
257 // Templates template.
260 template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
262 typedef Templates$n<$for i, [[T$i]]> type;
266 struct Templates<$for i, [[NoneT]]> {
267 typedef Templates0 type;
274 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
275 struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
276 typedef Templates$i<$for j, [[T$j]]> type;
281 // The TypeList template makes it possible to use either a single type
282 // or a Types<...> list in TYPED_TEST_SUITE() and
283 // INSTANTIATE_TYPED_TEST_SUITE_P().
285 template <typename T>
287 typedef Types1<T> type;
292 template <$for i, [[typename T$i]]>
293 struct TypeList<Types<$for i, [[T$i]]> > {
294 typedef typename Types<$for i, [[T$i]]>::type type;
297 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
299 } // namespace internal
300 } // namespace testing
302 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_