Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.tuple.helpers.cpp
Go to the documentation of this file.
1
29#include <rw_driver.h>
30
31// compile out all test code if extensions disabled
32#if !defined (_RWSTD_NO_EXT_CXX_0X) \
33 && !defined (_RWSTD_NO_RVALUE_REFERENCES)
34
35#include <tuple>
36
37#include "20.tuple.h"
38
39
41static void
42test_tuple_size ()
43{
44 rw_info (0, __FILE__, __LINE__, "tuple_size");
45
46#define STRING(x) #x
47#define TEST(T, S) \
48 rw_assert (std::tuple_size<T>::value == S, __FILE__, __LINE__, \
49 "tuple_size<" #T ">::value, got %d, expected " \
50 STRING (S), std::tuple_size<T>::value)
51
52 TEST (std::tuple<>, 0);
53
54 TEST (std::tuple<int>, 1);
55 TEST (std::tuple<const int>, 1);
56 TEST (std::tuple<UserDefined>, 1);
57 TEST (std::tuple<std::tuple<int> >, 1);
58
59#undef TUPLE
60#define TUPLE std::tuple<long, const char*>
61
62 TEST (TUPLE, 2);
63
64#undef TUPLE
65#define TUPLE std::tuple<bool, char, int, double, void*, UserDefined>
66
67 TEST (TUPLE, 6);
68}
69
70
72#include <rw/_meta_rel.h>
73
74#include <rw_any.h>
75
76class any_t : public rw_any_t
77{
78private:
79 enum {
80 inherited,
81 const_int,
82 user_defined,
83 int_tuple
84 } type_id;
85
86public:
87
88 template <class Type>
90 : rw_any_t (Type ()), type_id (inherited) { }
91
92 any_t (const int)
93 : rw_any_t (char ()), type_id (const_int) { }
94
96 : rw_any_t (char ()), type_id (user_defined) { }
97
98 any_t (std::tuple< int >)
99 : rw_any_t (char ()), type_id (int_tuple) { }
100
101 const char* type_name () const
102 {
103 return type_id == const_int? "const int":
104 type_id == user_defined? "UserDefined":
105 type_id == int_tuple? "std::tuple<int>":
107 }
108};
109
110static void
111test_tuple_element ()
112{
113 rw_info (0, __FILE__, __LINE__, "tuple_element");
114
115#undef IS_SAME
116#define IS_SAME(T,U) \
117 _RW::__rw_is_same<T, U>::value
118
119#undef TYPE_NAME
120#define TYPE_NAME(T) \
121 (any_t (T ())).type_name ()
122
123#undef TEST
124#define TEST(N, T, E) \
125{ \
126 typedef std::tuple_element<N, T>::type elem_type; \
127 rw_assert (IS_SAME(elem_type, E), __FILE__, __LINE__, \
128 "tuple_element<0, " #T ">::type, got type \"%s\", " \
129 "expected type \"" #E "\"", TYPE_NAME (elem_type)); \
130}
131
132 TEST (0, std::tuple<int>, int)
133 TEST (0, std::tuple<const int>, const int)
134 TEST (0, std::tuple<std::tuple<int> >, std::tuple<int>)
135 TEST (0, std::tuple<UserDefined>, UserDefined)
136
137#undef TUPLE
138#define TUPLE std::tuple<long, const char*>
139
140 TEST (0, TUPLE, long)
141 TEST (1, TUPLE, const char*)
142
143#undef TUPLE
144#define TUPLE std::tuple<bool, char, int, double, void*, UserDefined>
145
146 TEST (0, TUPLE, bool)
147 TEST (1, TUPLE, char)
148 TEST (2, TUPLE, int)
149 TEST (3, TUPLE, double)
150 TEST (4, TUPLE, void*)
152}
153
154
156static int
157run_test (int /*argc*/, char* /*argv*/ [])
158{
159 test_tuple_size ();
160 test_tuple_element ();
161
162 return 0;
163}
164
165#else // _RWSTD_NO_EXT_CXX_0X || _RWSTD_NO_RVALUE_REFERENCES
166
167static int
168run_test (int, char*[])
169{
170
171#if defined (_RWSTD_NO_EXT_CXX_0X)
172
173 rw_warn (0, 0, __LINE__,
174 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
175
176#elif defined (_RWSTD_NO_RVALUE_REFERENCES)
177
178 rw_warn (0, 0, __LINE__,
179 "test disabled because _RWSTD_NO_RVALUE_REFERENCES is "
180 "defined");
181
182#endif
183
184 return 0;
185}
186
187#endif // _RWSTD_NO_EXT_CXX_0X || _RWSTD_NO_RVALUE_REFERENCES
188
189/*extern*/ int
190main (int argc, char* argv [])
191{
192 return rw_test (argc, argv, __FILE__,
193 "[tuple.helper]",
194 "20.3.1.4 Tuple helper classes",
195 run_test, "", 0);
196}
197
#define TEST(T, S)
#define TUPLE
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
const char * type_name() const
any_t(UserDefined)
any_t(std::tuple< int >)
any_t(const int)
const char * type_name() const
Definition any.cpp:310
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647