32#if !defined (_RWSTD_NO_EXT_CXX_0X) \
33 && !defined(_RWSTD_NO_RVALUE_REFERENCES)
50template <
class T,
class U = T>
57bool equal (
const float&
x,
const float&
y)
63bool equal (
const char*
const&
x,
const char*
const&
y)
65 return 0 == std::strcmp (
x,
y);
69template <
class T,
class U>
71 const T&
t,
const U&
u)
76 "get<%d, %s> (); got %{@}, expected %{@}",
77 index, tuple_name, fmtT,
t, fmtU,
u);
84 "get<%d, %s> (); got %p [%d], expected %p [%d]",
85 index, tuple_name, &
t,
t.value (), &
u,
u.value ());
91 a = UserDefined::actual.N; e = UserDefined::expect.N; \
92 rw_assert (a == e, __FILE__, line, \
93 "UserDefined::" #N "; got %u, expected %u", a, e)
104template <
class T,
class U>
106 const std::tuple<T>&
t,
const std::tuple<U>&
u)
111 "get<%d, %s> (); got %{@}, expected %{@}",
113 fmtT, std::get<0> (
t), fmtU, std::get<0> (
u));
117template <
unsigned Index,
class Tuple,
class... Elements>
122template <
unsigned Index,
class Tuple>
127template <
unsigned Index,
class Tuple,
class Element,
class... Elements>
130 const Element&
value,
const Elements&... values)
134 std::get<Index> (tuple),
value);
136 test_impl<Index+1> (
line, tuple, values...);
139template <
class Tuple,
class... Elements>
143 test_impl<0> (
line, tuple, values...);
151 rw_info (0, __FILE__, __LINE__,
"default constructor");
164 std::tuple<bool, char, int, double, void*, UserDefined> bt;
170 "std::tuple<UserDefined> ut; called %d default ctors, "
177test_value_copy_ctor ()
179 rw_info (0, __FILE__, __LINE__,
"value copy constructor");
181 const int i = std::rand ();
182 std::tuple<int> it1 (
i);
183 test (__LINE__, it1,
i);
185 const std::tuple<int> it2 (
i);
186 test (__LINE__, it2,
i);
188 std::tuple<const int> ct (
i);
189 test (__LINE__, ct,
i);
191 int j = std::rand ();
192 const std::tuple<int&> rt (
j);
193 test (__LINE__, rt,
j);
195 std::tuple<std::tuple<int> > nt (it2);
197 test (__LINE__, nt, it2);
199 const long l = std::rand ();
200 std::tuple<long, const char*> pt (l,
"string");
201 test (__LINE__, pt, l, (
const char*)
"string");
205 std::tuple<UserDefined> ut (ud);
207 test (__LINE__, ut, ud);
209 const bool b =
true;
const char c =
'a';
210 const double d = 3.14159;
void*
const p = (
void*) &
i;
211 std::tuple<bool, char, int, double, void*, UserDefined>
212 bt (
b,
c,
i,
d,
p, ud);
220test_value_move_ctor ()
222 rw_info (0, __FILE__, __LINE__,
"value move constructor");
224#define INTEGER_CONSTANT 256
228 const int c = std::rand ();
230 std::tuple<int> it2 (
i);
231 test (__LINE__, it2,
c);
236 const std::tuple<int> it4 (
i);
237 test (__LINE__, it4,
c);
242 std::tuple<const int> ct2 (
i);
243 test (__LINE__, ct2,
c);
247 std::tuple<std::tuple<int> > nt (it1);
248 test (__LINE__, nt, it1);
250 std::tuple<long, const char*> pt (123456789L,
"string");
251 test (__LINE__, pt, 123456789L, (
const char*)
"string");
256 std::tuple<UserDefined> ut (
tmp);
258 test (__LINE__, ut, src);
261 std::tuple<bool, char, int, double, void*, UserDefined>
271test_homo_copy_ctor ()
273 rw_info (0, __FILE__, __LINE__,
274 "copy constructor (homogenous tuples)");
276 std::tuple<> et1, et2 (et1);
279 const int ci = std::rand ();
280 const std::tuple<int> it1 (ci);
281 std::tuple<int> it2 (it1);
282 test (__LINE__, it2, ci);
284 const std::tuple<const int>& ct1 = it1;
285 std::tuple<const int> ct2 (ct1);
286 test (__LINE__, ct2, ci);
289 const std::tuple<int&> rt1 (
i);
290 std::tuple<int&> rt2 (rt1);
291 test (__LINE__, rt2, ci);
293 const std::tuple<std::tuple<int> > nt1 (it1);
294 std::tuple<std::tuple<int> > nt2 (nt1);
295 test (__LINE__, nt2, it1);
297 const std::tuple<long, const char*> pt1 (1234567890L,
"string");
298 std::tuple<long, const char*> pt2 (pt1);
299 test (__LINE__, pt2, 1234567890L, (
const char*)
"string");
302 const std::tuple<UserDefined> ut1 (ud);
304 std::tuple<UserDefined> ut2 (ut1);
306 test (__LINE__, ut2, ud);
308 const std::tuple<bool, char, int, double, void*, UserDefined>
309 bt1 (
true,
'a', ci, 3.14159, (
void*
const) &
i, ud);
311 std::tuple<bool, char, int, double, void*, UserDefined> bt2 (bt1);
313 test (__LINE__, bt2,
true,
'a', ci, 3.14159, (
void*
const) &
i, ud);
319test_homo_move_ctor ()
321 rw_info (0, __FILE__, __LINE__,
322 "move constructor (homogenous tuples)");
326 const int ci = std::rand ();
328 std::tuple<int> it1 (ci);
329 std::tuple<int> it2 (std::move (it1));
330 test (__LINE__, it2, ci);
332 std::tuple<const int> ct1 (ci);
333 std::tuple<const int> ct2 = std::move (ct1);
334 test (__LINE__, ct2, ci);
336 std::tuple<std::tuple<int> > nt1 (it1);
337 std::tuple<std::tuple<int> > nt2 = std::move (nt1);
338 test (__LINE__, nt2, it1);
340 std::tuple<long, const char*> pt1 (1234567890L,
"string");
341 std::tuple<long, const char*> pt2 (std::move (pt1));
342 test (__LINE__, pt2, 1234567890L, (
const char*)
"string");
345 std::tuple<UserDefined> ut1 (ud);
347 std::tuple<UserDefined> ut2 (std::move (ut1));
349 test (__LINE__, ut2, ud);
351 std::tuple<bool, char, int, double, void*, UserDefined>
352 bt1 (
true,
'a', ci, 3.14159, (
void*) &ci, ud);
354 std::tuple<bool, char, int, double, void*, UserDefined>
355 bt2 (std::move (bt1));
357 test (__LINE__, bt2,
true,
'a', ci, 3.14159, (
void*) &ci, ud);
363test_homo_copy_assign ()
365 rw_info (0, __FILE__, __LINE__,
366 "copy assignment operator (homogenous tuples)");
368 const std::tuple<> et1 = std::tuple<> ();
373 int i = std::rand ();
374 const std::tuple<int> it1 (
i);
377 test (__LINE__, it2,
i);
381 const std::tuple<int&> rt1 (
i);
383 std::tuple<int&> rt2 (
j);
385 test (__LINE__, rt2,
i);
387 std::tuple<std::tuple<int> > nt1 (it1);
388 std::tuple<std::tuple<int> > nt2;
390 test (__LINE__, nt2, it1);
392 const std::tuple<long, const char*> pt1 (
long (
i),
"string");
393 std::tuple<long, const char*> pt2;
395 test (__LINE__, pt2,
long (
i), (
const char*)
"string");
398 const std::tuple<UserDefined> ut1 (ud);
399 std::tuple<UserDefined> ut2;
402 test (__LINE__, ut2, ud);
404 const std::tuple<bool, char, int, double, void*, UserDefined>
405 bt1 (
true,
'a',
i, 3.14159, (
void*
const) &
i, ud);
407 std::tuple<bool, char, int, double, void*, UserDefined> bt2;
410 test (__LINE__, bt2,
true,
'a',
i, 3.14159, (
void*
const) &
i, ud);
416test_homo_move_assign ()
418 rw_info (0, __FILE__, __LINE__,
419 "move assignment operator (homogenous tuples)");
421 std::tuple<> et1, et2;
422 et2 = std::move (et1);
425 int i = std::rand ();
427 std::tuple<int> it1 (
i);
429 it2 = std::move (it1);
430 test (__LINE__, it2,
i);
434 std::tuple<std::tuple<int> > nt1 (it2);
435 std::tuple<std::tuple<int> > nt2;
436 nt2 = std::move (nt1);
437 test (__LINE__, nt2, it2);
439 std::tuple<long, const char*> pt1 (1234567890L,
"string");
440 std::tuple<long, const char*> pt2;
441 pt2 = std::move (pt1);
442 test (__LINE__, pt2, 1234567890L, (
const char*)
"string");
445 std::tuple<UserDefined> ut1 (ud);
446 std::tuple<UserDefined> ut2;
449 test (__LINE__, ut2, ud);
451 std::tuple<bool, char, int, double, void*, UserDefined>
452 bt1 (
true,
'a',
i, 3.14159, (
void*
const) &
i, ud);
453 std::tuple<bool, char, int, double, void*, UserDefined> bt2;
456 test (__LINE__, bt2,
true,
'a',
i, 3.14159, (
void*
const) &
i, ud);
470 operator const char* ()
const {
return this->
data (); }
475test_hetero_copy_ctor ()
477 rw_info (0, __FILE__, __LINE__,
478 "copy constructor (heterogenous tuples)");
482 const std::tuple<char> cit (
static_cast<char> (
i));
483 std::tuple<int> it (cit);
484 test (__LINE__, it,
i);
486 std::tuple<unsigned, String>
cpt (12345U,
"string");
487 std::tuple<long, const char*> pt (
cpt);
488 test (__LINE__, pt, 12345U, (
const char*)
"string");
491 const std::tuple<int, int, short, float, char*, UserDefined>
492 cbt (
int (
true),
int (
'a'),
short (
i), 3.14159f,
s, ud);
494 std::tuple<bool, char, int, double, void*, UserDefined> bt (cbt);
496 test (__LINE__, bt,
true,
'a',
i, 3.14159f,
s, ud);
502test_hetero_move_ctor ()
504 rw_info (0, __FILE__, __LINE__,
505 "move constructor (heterogenous tuples)");
509 std::tuple<char> cit (
static_cast<char> (
i));
510 std::tuple<int> it (std::move (cit));
511 test (__LINE__, it,
i);
513 std::tuple<unsigned, String>
cpt (12345U,
"string");
514 std::tuple<long, const char*> pt (std::move (
cpt));
515 test (__LINE__, pt, 12345U, (
const char*)
"string");
518 std::tuple<int, int, short, float, char*, UserDefined>
519 cbt (
int (
true),
int (
'a'),
short (
i), 3.14159f,
s, ud);
521 std::tuple<bool, char, int, double, void*, UserDefined>
522 bt (std::move (cbt));
524 test (__LINE__, bt,
true,
'a',
i, 3.14159f,
s, ud);
530test_hetero_copy_assign ()
532 rw_info (0, __FILE__, __LINE__,
533 "copy assignment operator (heterogenous tuples)");
537 std::tuple<char> cit (
static_cast<char> (
i));
540 test (__LINE__, it,
i);
542 std::tuple<unsigned, String>
cpt (12345U,
"string");
543 std::tuple<long, const char*> pt;
545 test (__LINE__, pt, 12345U, (
const char*)
"string");
548 std::tuple<int, int, short, float, char*, UserDefined>
549 cbt (
int (
true),
int (
'a'),
short (
i), 3.14159f,
s, ud);
550 std::tuple<bool, char, int, double, void*, UserDefined> bt;
553 test (__LINE__, bt,
true,
'a',
i, 3.14159f,
s, ud);
559test_hetero_move_assign ()
561 rw_info (0, __FILE__, __LINE__,
562 "move assignment operator (heterogenous tuples)");
566 std::tuple<char> cit (
i);
568 it = std::move (cit);
569 test (__LINE__, it,
i);
571 std::tuple<unsigned, String>
cpt (12345U,
"string");
572 std::tuple<long, const char*> pt;
573 pt = std::move (
cpt);
574 test (__LINE__, pt, 12345U, (
const char*)
"string");
577 std::tuple<int, int, short, float, char*, UserDefined>
578 cbt (
int (
true),
int (
'a'),
short (
i), 3.14159f,
s, ud);
579 std::tuple<bool, char, int, double, void*, UserDefined> bt;
583 test (__LINE__, bt,
true,
'a',
i, 3.14159f,
s, ud);
591 rw_info (0, __FILE__, __LINE__,
592 "user-defined allocator constructors");
603 test_value_copy_ctor ();
604 test_value_move_ctor ();
606 test_homo_copy_ctor ();
607 test_homo_move_ctor ();
608 test_homo_copy_assign ();
609 test_homo_move_assign ();
611 test_hetero_copy_ctor ();
612 test_hetero_move_ctor ();
613 test_hetero_copy_assign ();
614 test_hetero_move_assign ();
626#if defined (_RWSTD_NO_EXT_CXX_OX)
629 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
631#elif defined (_RWSTD_NO_RVALUE_REFERENCES)
634 "test disabled because _RWSTD_NO_RVALUE_REFERENCES is "
647 return rw_test (argc, argv, __FILE__,
648 "[tuple.cnstr]",
"20.3.1.2 Construction",
void test_impl(int line, const Tuple &tuple, const Elements &... values)
bool equal(const T &x, const U &y)
std::tuple< bool, char, int, double, void *, UserDefined > Tuple
void test_default_ctor(std::bitset< N > *)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_UNUSED(arg)
_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 *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_fltcmp(float x, float y)