Author: elemings Date: Fri Jul 18 11:05:55 2008 New Revision: 677985 URL: http://svn.apache.org/viewvc?rev=677985&view=rev Log: 2008-07-18 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-958 * include/rw/_tuple.h (operator==): Minor formatting change. (operator<): Fixed lexicographical comparison logic. * tests/utilities/20.tuple.h: Remove global tuple typedefs and unused output opeator<<. * tests/utilities/20.tuple.cnstr.cpp: Replaced typedefs with explicit tuple types. Added TUPLE macros where tuple types containing commas are used as function macro arguments. * tests/utilities/20.tuple.creation.cpp: Same. * tests/utilities/20.tuple.elem.cpp: Same. * tests/utilities/20.tuple.helpers.cpp: Same. * tests/utilities/20.tuple.rel.cpp: Same. Also added more tests (which uncovered broken `operator<') and concise TEST() function macro wrapper. Modified: stdcxx/branches/4.3.x/include/rw/_tuple.h stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp stdcxx/branches/4.3.x/tests/utilities/20.tuple.creation.cpp stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp stdcxx/branches/4.3.x/tests/utilities/20.tuple.h stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp stdcxx/branches/4.3.x/tests/utilities/20.tuple.rel.cpp Modified: stdcxx/branches/4.3.x/include/rw/_tuple.h URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/rw/_tuple.h?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/include/rw/_tuple.h (original) +++ stdcxx/branches/4.3.x/include/rw/_tuple.h Fri Jul 18 11:05:55 2008 @@ -210,7 +210,7 @@ template <class... _TypesT, class... _TypesU> bool operator== (const __rw_tuple<_TypesT...>& __x, const __rw_tuple<_TypesU...>& __y) { - return (__x._C_head () == __y._C_head ()) + return (__x._C_head () == __y._C_head ()) && (__x._C_tail () == __y._C_tail ()); } @@ -223,8 +223,9 @@ template <class... _TypesT, class... _TypesU> bool operator< (const __rw_tuple<_TypesT...>& __x, const __rw_tuple<_TypesU...>& __y) { - return (__x._C_head () < __y._C_head ()) - || (__y._C_tail () < __x._C_tail ()); + return (__x._C_head () < __y._C_head ()) + || ( !(__y._C_head () < __x._C_head ()) + && (__x._C_tail () < __y._C_tail ())); } _RWSTD_SPECIALIZED_FUNCTION Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp Fri Jul 18 11:05:55 2008 @@ -39,6 +39,7 @@ #include <type_traits> // for decay #include <rw_valcmp.h> // for rw_fltcmp +#include <rw_allocator.h> // for UserAlloc #include "20.tuple.h" @@ -149,18 +150,24 @@ { rw_info (0, __FILE__, __LINE__, "default constructor"); - EmptyTuple et; _RWSTD_UNUSED (et); - IntTuple it; _RWSTD_UNUSED (it); - ConstIntTuple ct; _RWSTD_UNUSED (ct); + std::tuple<> et; _RWSTD_UNUSED (et); + // TODO: enable this test after implementing empty space optimization + //rw_assert (sizeof (et) == 0, __FILE__, __LINE__, + //"sizeof (std::tuple<>); got %u, expected 0", + //sizeof (et)); + + std::tuple<int> it; _RWSTD_UNUSED (it); + std::tuple<const int> ct; _RWSTD_UNUSED (ct); // ill-formed for tuples with element types containing references - PairTuple pt; _RWSTD_UNUSED (pt); - NestedTuple nt; _RWSTD_UNUSED (nt); - BigTuple bt; _RWSTD_UNUSED (bt); + std::tuple<long, const char*> pt; _RWSTD_UNUSED (pt); + std::tuple<std::tuple<int> > nt; _RWSTD_UNUSED (nt); + std::tuple<bool, char, int, double, void*, UserDefined> bt; + _RWSTD_UNUSED (bt); UserDefined::reset (); - UserTuple ut; _RWSTD_UNUSED (ut); + std::tuple<UserDefined> ut; _RWSTD_UNUSED (ut); rw_assert (1 == UserDefined::actual.dflt_ctor, __FILE__, __LINE__, - "UserTuple::UserTuple (); called %d default ctors, " + "std::tuple<UserDefined> ut; called %d default ctors, " "expected 1", UserDefined::actual.dflt_ctor); } @@ -172,36 +179,37 @@ rw_info (0, __FILE__, __LINE__, "value copy constructor"); const int i = std::rand (); - IntTuple it1 (i); + std::tuple<int> it1 (i); test (__LINE__, it1, i); - const IntTuple it2 (i); + const std::tuple<int> it2 (i); test (__LINE__, it2, i); - ConstIntTuple ct (i); + std::tuple<const int> ct (i); test (__LINE__, ct, i); int j = std::rand (); - const IntRefTuple rt (j); + const std::tuple<int&> rt (j); test (__LINE__, rt, j); - NestedTuple nt (it2); + std::tuple<std::tuple<int> > nt (it2); //std::get<0> (it2) = std::rand (); // diliberately cause assertion test (__LINE__, nt, it2); const long l = std::rand (); - PairTuple pt (l, "string"); + std::tuple<long, const char*> pt (l, "string"); test (__LINE__, pt, l, (const char*) "string"); const UserDefined ud (i); UserDefined::reset (); - UserTuple ut (ud); + std::tuple<UserDefined> ut (ud); UserDefined::expect.copy_ctor = 1; test (__LINE__, ut, ud); const bool b = true; const char c = 'a'; const double d = 3.14159; void* const p = (void*) &i; - BigTuple bt (b, c, i, d, p, ud); + std::tuple<bool, char, int, double, void*, UserDefined> + bt (b, c, i, d, p, ud); ++UserDefined::expect.copy_ctor; test (__LINE__, bt, b, c, i, d, p, ud); } @@ -215,42 +223,43 @@ #define INTEGER_CONSTANT 256 - IntTuple it1 (INTEGER_CONSTANT); + std::tuple<int> it1 (INTEGER_CONSTANT); test (__LINE__, it1, INTEGER_CONSTANT); const int c = std::rand (); int i = c; // move semantics can alter source value - IntTuple it2 (i); // temporary source value + std::tuple<int> it2 (i); // temporary source value test (__LINE__, it2, c); - const IntTuple it3 (INTEGER_CONSTANT); + const std::tuple<int> it3 (INTEGER_CONSTANT); test (__LINE__, it3, INTEGER_CONSTANT); i = c; - const IntTuple it4 (i); + const std::tuple<int> it4 (i); test (__LINE__, it4, c); - ConstIntTuple ct1 (INTEGER_CONSTANT); + std::tuple<const int> ct1 (INTEGER_CONSTANT); test (__LINE__, ct1, INTEGER_CONSTANT); i = c; - ConstIntTuple ct2 (i); + std::tuple<const int> ct2 (i); test (__LINE__, ct2, c); // ill-formed for tuples with element types containing references - NestedTuple nt (it1); + std::tuple<std::tuple<int> > nt (it1); test (__LINE__, nt, it1); - PairTuple pt (123456789L, "string"); + std::tuple<long, const char*> pt (123456789L, "string"); test (__LINE__, pt, 123456789L, (const char*) "string"); const UserDefined src (c); UserDefined tmp (src); UserDefined::reset (); - UserTuple ut (tmp); + std::tuple<UserDefined> ut (tmp); UserDefined::expect.move_ctor = 1; test (__LINE__, ut, src); tmp = src; ++UserDefined::expect.copy_asgn; - BigTuple bt (true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, tmp); + std::tuple<bool, char, int, double, void*, UserDefined> + bt (true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, tmp); ++UserDefined::expect.move_ctor; test (__LINE__, bt, true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, src); @@ -264,41 +273,42 @@ rw_info (0, __FILE__, __LINE__, "copy constructor (homogenous tuples)"); - EmptyTuple et1, et2 (et1); + std::tuple<> et1, et2 (et1); _RWSTD_UNUSED (et2); const int ci = std::rand (); - const IntTuple it1 (ci); - IntTuple it2 (it1); + const std::tuple<int> it1 (ci); + std::tuple<int> it2 (it1); test (__LINE__, it2, ci); - const ConstIntTuple& ct1 = it1; // same as copy ctor - ConstIntTuple ct2 (ct1); + const std::tuple<const int>& ct1 = it1; // same as copy ctor + std::tuple<const int> ct2 (ct1); test (__LINE__, ct2, ci); int i = ci; - const IntRefTuple rt1 (i); - IntRefTuple rt2 (rt1); + const std::tuple<int&> rt1 (i); + std::tuple<int&> rt2 (rt1); test (__LINE__, rt2, ci); - const NestedTuple nt1 (it1); - NestedTuple nt2 (nt1); + const std::tuple<std::tuple<int> > nt1 (it1); + std::tuple<std::tuple<int> > nt2 (nt1); test (__LINE__, nt2, it1); - const PairTuple pt1 (1234567890L, "string"); - PairTuple pt2 (pt1); + const std::tuple<long, const char*> pt1 (1234567890L, "string"); + std::tuple<long, const char*> pt2 (pt1); test (__LINE__, pt2, 1234567890L, (const char*) "string"); UserDefined ud (ci); - const UserTuple ut1 (ud); + const std::tuple<UserDefined> ut1 (ud); UserDefined::reset (); - UserTuple ut2 (ut1); + std::tuple<UserDefined> ut2 (ut1); ++UserDefined::expect.copy_ctor; test (__LINE__, ut2, ud); - const BigTuple bt1 (true, 'a', ci, 3.14159, (void* const) &i, ud); + const std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', ci, 3.14159, (void* const) &i, ud); ++UserDefined::expect.move_ctor; // moved ud to bt1 - BigTuple bt2 (bt1); + std::tuple<bool, char, int, double, void*, UserDefined> bt2 (bt1); ++UserDefined::expect.copy_ctor; // copied to bt2 test (__LINE__, bt2, true, 'a', ci, 3.14159, (void* const) &i, ud); } @@ -311,36 +321,38 @@ rw_info (0, __FILE__, __LINE__, "move constructor (homogenous tuples)"); - EmptyTuple et (EmptyTuple ()); _RWSTD_UNUSED (et); + std::tuple<> et (std::tuple<> ()); _RWSTD_UNUSED (et); const int ci = std::rand (); - IntTuple it1 (ci); - IntTuple it2 (std::move (it1)); + std::tuple<int> it1 (ci); + std::tuple<int> it2 (std::move (it1)); test (__LINE__, it2, ci); - ConstIntTuple ct1 (ci); - ConstIntTuple ct2 = std::move (ct1); + std::tuple<const int> ct1 (ci); + std::tuple<const int> ct2 = std::move (ct1); test (__LINE__, ct2, ci); - NestedTuple nt1 (it1); - NestedTuple nt2 = std::move (nt1); + std::tuple<std::tuple<int> > nt1 (it1); + std::tuple<std::tuple<int> > nt2 = std::move (nt1); test (__LINE__, nt2, it1); - PairTuple pt1 (1234567890L, "string"); - PairTuple pt2 (std::move (pt1)); + std::tuple<long, const char*> pt1 (1234567890L, "string"); + std::tuple<long, const char*> pt2 (std::move (pt1)); test (__LINE__, pt2, 1234567890L, (const char*) "string"); const UserDefined ud (ci); - UserTuple ut1 (ud); + std::tuple<UserDefined> ut1 (ud); UserDefined::reset (); - UserTuple ut2 (std::move (ut1)); + std::tuple<UserDefined> ut2 (std::move (ut1)); ++UserDefined::expect.move_ctor; test (__LINE__, ut2, ud); - BigTuple bt1 (true, 'a', ci, 3.14159, (void*) &ci, ud); + std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', ci, 3.14159, (void*) &ci, ud); ++UserDefined::expect.copy_ctor; - BigTuple bt2 (std::move (bt1)); + std::tuple<bool, char, int, double, void*, UserDefined> + bt2 (std::move (bt1)); ++UserDefined::expect.move_ctor; test (__LINE__, bt2, true, 'a', ci, 3.14159, (void*) &ci, ud); } @@ -353,45 +365,47 @@ rw_info (0, __FILE__, __LINE__, "copy assignment operator (homogenous tuples)"); - const EmptyTuple et1 = EmptyTuple (); - EmptyTuple et2; + const std::tuple<> et1 = std::tuple<> (); + std::tuple<> et2; et2 = et1; _RWSTD_UNUSED (et2); int i = std::rand (); - const IntTuple it1 (i); - IntTuple it2; + const std::tuple<int> it1 (i); + std::tuple<int> it2; it2 = it1; test (__LINE__, it2, i); // copy assignment ill-formed for constant element types - const IntRefTuple rt1 (i); + const std::tuple<int&> rt1 (i); int j = -1; // outside range of rand() - IntRefTuple rt2 (j); // note, different reference + std::tuple<int&> rt2 (j); // note, different reference rt2 = rt1; test (__LINE__, rt2, i); - NestedTuple nt1 (it1); - NestedTuple nt2; + std::tuple<std::tuple<int> > nt1 (it1); + std::tuple<std::tuple<int> > nt2; nt2 = nt1; test (__LINE__, nt2, it1); - const PairTuple pt1 (long (i), "string"); - PairTuple pt2; + const std::tuple<long, const char*> pt1 (long (i), "string"); + std::tuple<long, const char*> pt2; pt2 = pt1; test (__LINE__, pt2, long (i), (const char*) "string"); const UserDefined ud (i); - const UserTuple ut1 (ud); - UserTuple ut2; + const std::tuple<UserDefined> ut1 (ud); + std::tuple<UserDefined> ut2; UserDefined::reset (); ut2 = ut1; ++UserDefined::expect.copy_asgn; test (__LINE__, ut2, ud); - const BigTuple bt1 (true, 'a', i, 3.14159, (void* const) &i, ud); + const std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', i, 3.14159, (void* const) &i, ud); ++UserDefined::expect.copy_ctor; - BigTuple bt2; ++UserDefined::expect.dflt_ctor; + std::tuple<bool, char, int, double, void*, UserDefined> bt2; + ++UserDefined::expect.dflt_ctor; bt2 = bt1; ++UserDefined::expect.copy_asgn; test (__LINE__, bt2, true, 'a', i, 3.14159, (void* const) &i, ud); } @@ -404,38 +418,39 @@ rw_info (0, __FILE__, __LINE__, "move assignment operator (homogenous tuples)"); - EmptyTuple et1, et2; + std::tuple<> et1, et2; et2 = std::move (et1); _RWSTD_UNUSED (et2); int i = std::rand (); - IntTuple it1 (i); - IntTuple it2; + std::tuple<int> it1 (i); + std::tuple<int> it2; it2 = std::move (it1); test (__LINE__, it2, i); // move assignment ill-formed for constant element types - NestedTuple nt1 (it2); - NestedTuple nt2; + std::tuple<std::tuple<int> > nt1 (it2); + std::tuple<std::tuple<int> > nt2; nt2 = std::move (nt1); test (__LINE__, nt2, it2); - PairTuple pt1 (1234567890L, "string"); - PairTuple pt2; + std::tuple<long, const char*> pt1 (1234567890L, "string"); + std::tuple<long, const char*> pt2; pt2 = std::move (pt1); test (__LINE__, pt2, 1234567890L, (const char*) "string"); const UserDefined ud (i); - UserTuple ut1 (ud); - UserTuple ut2; + std::tuple<UserDefined> ut1 (ud); + std::tuple<UserDefined> ut2; UserDefined::reset (); ut2 = std::move (ut1); ++UserDefined::expect.move_asgn; test (__LINE__, ut2, ud); - BigTuple bt1 (true, 'a', i, 3.14159, (void* const) &i, ud); - BigTuple bt2; + std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', i, 3.14159, (void* const) &i, ud); + std::tuple<bool, char, int, double, void*, UserDefined> bt2; UserDefined::reset (); bt2 = std::move (bt1); ++UserDefined::expect.move_asgn; test (__LINE__, bt2, true, 'a', i, 3.14159, (void* const) &i, ud); @@ -455,10 +470,6 @@ operator const char* () const { return this->data (); } }; -typedef std::tuple<char> CompatIntTuple; -typedef std::tuple<unsigned, String> CompatPairTuple; -typedef std::tuple<int, int, short, float, - char*, UserDefined> CompatBigTuple; static void test_hetero_copy_ctor () @@ -468,19 +479,20 @@ int i = std::rand () % CHAR_MAX; - const CompatIntTuple cit (static_cast<char> (i)); - IntTuple it (cit); + const std::tuple<char> cit (static_cast<char> (i)); + std::tuple<int> it (cit); test (__LINE__, it, i); - CompatPairTuple cpt (12345U, "string"); - PairTuple pt (cpt); + std::tuple<unsigned, String> cpt (12345U, "string"); + std::tuple<long, const char*> pt (cpt); test (__LINE__, pt, 12345U, (const char*) "string"); char s [] = "string"; const UserDefined ud (i); - const CompatBigTuple cbt (int (true), int ('a'), short (i), - 3.14159f, s, ud); + const std::tuple<int, int, short, float, char*, UserDefined> + cbt (int (true), int ('a'), short (i), 3.14159f, s, ud); UserDefined::reset (); - BigTuple bt (cbt); ++UserDefined::expect.copy_ctor; + std::tuple<bool, char, int, double, void*, UserDefined> bt (cbt); + ++UserDefined::expect.copy_ctor; test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud); } @@ -494,19 +506,21 @@ int i = std::rand () % CHAR_MAX; - CompatIntTuple cit (static_cast<char> (i)); - IntTuple it (std::move (cit)); + std::tuple<char> cit (static_cast<char> (i)); + std::tuple<int> it (std::move (cit)); test (__LINE__, it, i); - CompatPairTuple cpt (12345U, "string"); - PairTuple pt (std::move (cpt)); + std::tuple<unsigned, String> cpt (12345U, "string"); + std::tuple<long, const char*> pt (std::move (cpt)); test (__LINE__, pt, 12345U, (const char*) "string"); char s [] = "string"; const UserDefined ud (i); - CompatBigTuple cbt (int (true), int ('a'), short (i), - 3.14159f, s, ud); + std::tuple<int, int, short, float, char*, UserDefined> + cbt (int (true), int ('a'), short (i), 3.14159f, s, ud); UserDefined::reset (); - BigTuple bt (std::move (cbt)); ++UserDefined::expect.move_ctor; + std::tuple<bool, char, int, double, void*, UserDefined> + bt (std::move (cbt)); + ++UserDefined::expect.move_ctor; test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud); } @@ -520,20 +534,20 @@ int i = std::rand () % CHAR_MAX; - CompatIntTuple cit (static_cast<char> (i)); - IntTuple it; + std::tuple<char> cit (static_cast<char> (i)); + std::tuple<int> it; it = cit; test (__LINE__, it, i); - CompatPairTuple cpt (12345U, "string"); - PairTuple pt; + std::tuple<unsigned, String> cpt (12345U, "string"); + std::tuple<long, const char*> pt; pt = cpt; test (__LINE__, pt, 12345U, (const char*) "string"); char s [] = "string"; const UserDefined ud (i); - CompatBigTuple cbt (int (true), int ('a'), short (i), - 3.14159f, s, ud); - BigTuple bt; + std::tuple<int, int, short, float, char*, UserDefined> + cbt (int (true), int ('a'), short (i), 3.14159f, s, ud); + std::tuple<bool, char, int, double, void*, UserDefined> bt; UserDefined::reset (); bt = cbt; ++UserDefined::expect.copy_asgn; test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud); @@ -549,20 +563,21 @@ int i = std::rand () % CHAR_MAX; - CompatIntTuple cit (i); - IntTuple it; + std::tuple<char> cit (i); + std::tuple<int> it; it = std::move (cit); test (__LINE__, it, i); - CompatPairTuple cpt (12345U, "string"); - PairTuple pt; + std::tuple<unsigned, String> cpt (12345U, "string"); + std::tuple<long, const char*> pt; pt = std::move (cpt); test (__LINE__, pt, 12345U, (const char*) "string"); char s [] = "string"; const UserDefined ud (i); - CompatBigTuple cbt (int (true), int ('a'), short (i), - 3.14159f, s, ud); - BigTuple bt; ++UserDefined::expect.move_ctor; + std::tuple<int, int, short, float, char*, UserDefined> + cbt (int (true), int ('a'), short (i), 3.14159f, s, ud); + std::tuple<bool, char, int, double, void*, UserDefined> bt; + ++UserDefined::expect.move_ctor; UserDefined::reset (); bt = std::move (cbt); ++UserDefined::expect.move_asgn; test (__LINE__, bt, true, 'a', i, 3.14159f, s, ud); @@ -570,8 +585,6 @@ /**************************************************************************/ -#include <rw_allocator.h> // for UserAlloc - static void test_alloc_ctors () { Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.creation.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.creation.cpp?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.creation.cpp (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.creation.cpp Fri Jul 18 11:05:55 2008 @@ -46,17 +46,15 @@ { rw_info (0, __FILE__, __LINE__, "make_tuple"); - IntTuple it1 = std::make_tuple (1); + std::tuple<int> it1 = std::make_tuple (1); - typedef std::tuple<int, int> IntTuple2; int i = 2; - IntTuple2 it2 = std::make_tuple (1, i); + std::tuple<int, int> it2 = std::make_tuple (1, i); - typedef std::tuple<int, int, int> IntTuple3; const int j = 3; - IntTuple3 it3 = std::make_tuple (1, i, j); + std::tuple<int, int, int> it3 = std::make_tuple (1, i, j); - IntRefTuple rt1 = std::make_tuple (std::ref (i)); + std::tuple<int&> rt1 = std::make_tuple (std::ref (i)); std::tuple<const int&> rt2 = std::make_tuple (std::cref (i)); } @@ -89,16 +87,17 @@ { rw_info (0, __FILE__, __LINE__, "tuple_cat"); -#define Big1stPart bool, char, int, double -#define Big2ndPart void*, UserDefined +#define FirstHalf bool, char, int, double +#define SecondHalf void*, UserDefined - typedef std::tuple<Big1stPart> Big1stTuple; - Big1stTuple bt1 (true, 'a', 256, 3.14159); + typedef std::tuple<FirstHalf> FirstTuple; + FirstTuple t1 (true, 'a', 256, 3.14159); - typedef std::tuple<Big2ndPart> Big2ndTuple; - Big2ndTuple bt2 (&bt1, UserDefined ()); + typedef std::tuple<SecondHalf> SecondTuple; + SecondTuple t2 (&t1, UserDefined ()); - //BigTuple bt (tuple_cat (bt1, bt2)); + typedef std::tuple<FirstHalf, SecondHalf> WholeTuple; + //WholeTuple t3 (tuple_cat (t1, t2)); } /**************************************************************************/ Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp Fri Jul 18 11:05:55 2008 @@ -11,7 +11,7 @@ * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of + * except in compliance with the License. You may otain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -50,91 +50,93 @@ static void* ptr_val; static UserDefined user_val; +typedef std::tuple<bool, char, int, double, void*, UserDefined> Tuple; + static void -test_const_get (const BigTuple& bt) +test_const_get (const Tuple& t) { rw_info (0, __FILE__, __LINE__, "get (const)"); - const bool& b = std::get<0> (bt); - rw_assert (b == BOOL_VAL, __FILE__, __LINE__, "get<0>(bt), got %s, " + const bool& b = std::get<0> (t); + rw_assert (b == BOOL_VAL, __FILE__, __LINE__, "get<0>(t), got %s, " "expected %s", b? "true": "false", BOOL_VAL? "true": "false"); - const char& c = std::get<1> (bt); + const char& c = std::get<1> (t); rw_assert (c == CHAR_VAL, __FILE__, __LINE__, - "get<1>(bt), got \'%c\', expected \'%c\'", c, CHAR_VAL); + "get<1>(t), got \'%c\', expected \'%c\'", c, CHAR_VAL); - const int& i = std::get<2> (bt); + const int& i = std::get<2> (t); rw_assert (i == INT_VAL, __FILE__, __LINE__, - "get<2>(bt), got %d, expected %d", i, INT_VAL); + "get<2>(t), got %d, expected %d", i, INT_VAL); - const double& d = std::get<3> (bt); + const double& d = std::get<3> (t); rw_assert (0 == rw_dblcmp (d, DBL_VAL), __FILE__, __LINE__, - "get<3>(bt), got %f, expected %f", d, DBL_VAL); + "get<3>(t), got %f, expected %f", d, DBL_VAL); - void* const& p = std::get<4> (bt); + void* const& p = std::get<4> (t); rw_assert (p == PTR_VAL, __FILE__, __LINE__, - "get<4>(bt), got %p, expected %p", p, PTR_VAL); + "get<4>(t), got %p, expected %p", p, PTR_VAL); - const UserDefined& uc = std::get<5> (bt); + const UserDefined& uc = std::get<5> (t); rw_assert (uc == USER_VAL, __FILE__, __LINE__, - "get<5>(bt), got %d, expected %d", + "get<5>(t), got %d, expected %d", uc.value (), USER_VAL.value ()); } /**************************************************************************/ static void -test_get (BigTuple& bt) +test_get (Tuple& t) { rw_info (0, __FILE__, __LINE__, "get"); - bool& b = std::get<0> (bt); + bool& b = std::get<0> (t); rw_assert (b == BOOL_VAL, __FILE__, __LINE__, - "get<0>(bt), got %d, expected %b", b, BOOL_VAL); + "get<0>(t), got %d, expected %b", b, BOOL_VAL); b = !BOOL_VAL; - rw_assert (std::get<0> (bt) == !BOOL_VAL, __FILE__, __LINE__, - "get<0>(bt), got %d, expected %b", std::get<0> (bt), + rw_assert (std::get<0> (t) == !BOOL_VAL, __FILE__, __LINE__, + "get<0>(t), got %d, expected %b", std::get<0> (t), !BOOL_VAL); - char& c = std::get<1> (bt); + char& c = std::get<1> (t); rw_assert (c == 'a', __FILE__, __LINE__, - "get<1>(bt), got %c, expected \'%c\'", c, CHAR_VAL); + "get<1>(t), got %c, expected \'%c\'", c, CHAR_VAL); c = '1'; - rw_assert (std::get<1> (bt) == '1', __FILE__, __LINE__, - "get<1>(bt), got %c, expected \'1\'", std::get<1> (bt)); + rw_assert (std::get<1> (t) == '1', __FILE__, __LINE__, + "get<1>(t), got %c, expected \'1\'", std::get<1> (t)); - int& i = std::get<2> (bt); + int& i = std::get<2> (t); rw_assert (i == INT_VAL, __FILE__, __LINE__, - "get<2>(bt), got %d, expected %d", i, INT_VAL); + "get<2>(t), got %d, expected %d", i, INT_VAL); i = INT_VAL+1; - rw_assert (std::get<2> (bt) == INT_VAL+1, __FILE__, __LINE__, - "get<1>(bt), got %d, expected %d", std::get<2> (bt), + rw_assert (std::get<2> (t) == INT_VAL+1, __FILE__, __LINE__, + "get<1>(t), got %d, expected %d", std::get<2> (t), INT_VAL+1); - double& d = std::get<3> (bt); + double& d = std::get<3> (t); rw_assert (0 == rw_dblcmp (d, DBL_VAL), __FILE__, __LINE__, - "get<3>(bt), got %f, expected %f", d, DBL_VAL); + "get<3>(t), got %f, expected %f", d, DBL_VAL); d = DBL_VAL*DBL_VAL; - rw_assert (0 == rw_dblcmp (std::get<3> (bt), DBL_VAL*DBL_VAL), + rw_assert (0 == rw_dblcmp (std::get<3> (t), DBL_VAL*DBL_VAL), __FILE__, __LINE__, - "get<3>(bt), got %f, expected %f", std::get<3> (bt), + "get<3>(t), got %f, expected %f", std::get<3> (t), DBL_VAL*DBL_VAL); - void* p = std::get<4> (bt); + void* p = std::get<4> (t); rw_assert (p == PTR_VAL, __FILE__, __LINE__, - "get<4>(bt), got %p, expected %p", p, PTR_VAL); + "get<4>(t), got %p, expected %p", p, PTR_VAL); p = &d; - rw_assert (std::get<4> (bt) == &d, __FILE__, __LINE__, - "get<4>(bt), got %p, expected %p", std::get<4> (bt), &d); + rw_assert (std::get<4> (t) == &d, __FILE__, __LINE__, + "get<4>(t), got %p, expected %p", std::get<4> (t), &d); - UserDefined& uc = std::get<5> (bt); + UserDefined& uc = std::get<5> (t); rw_assert (uc == USER_VAL, __FILE__, __LINE__, - "get<5>(bt), got %d, expected %d", + "get<5>(t), got %d, expected %d", uc.value (), USER_VAL.value ()); uc = UserDefined (INT_VAL); - rw_assert ((std::get<5> (bt)).value () == INT_VAL, __FILE__, __LINE__, - "get<5>(bt), got %d, expected %d", - (std::get<5> (bt)).value (), INT_VAL); + rw_assert ((std::get<5> (t)).value () == INT_VAL, __FILE__, __LINE__, + "get<5>(t), got %d, expected %d", + (std::get<5> (t)).value (), INT_VAL); } /**************************************************************************/ @@ -143,10 +145,10 @@ run_test (int /*argc*/, char* argv []) { ptr_val = static_cast<void*> (argv [0]); - BigTuple bt (BOOL_VAL, CHAR_VAL, INT_VAL, DBL_VAL, PTR_VAL, USER_VAL); + Tuple t (BOOL_VAL, CHAR_VAL, INT_VAL, DBL_VAL, PTR_VAL, USER_VAL); - test_const_get (bt); - test_get (bt); + test_const_get (t); + test_get (t); return 0; } Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.h URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.h?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.h (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.h Fri Jul 18 11:05:55 2008 @@ -155,35 +155,8 @@ return lhs.value () < rhs.value (); } -inline std::ostream& -operator< (std::ostream& os, const UserDefined& src) -{ - os << "UserDefined@" << &src << " [value_ = " << src.value () << "]"; - return os; -} - /**************************************************************************/ -// various tuple types for test purposes - -typedef std::tuple <> EmptyTuple; - -typedef std::tuple <int> IntTuple; -typedef std::tuple <const int> ConstIntTuple; -typedef std::tuple <int&> IntRefTuple; - -typedef std::tuple <IntTuple> NestedTuple; - -typedef std::tuple <long, const char*> PairTuple; - -typedef std::tuple <UserDefined> UserTuple; - -#define BIG_TYPES bool, char, int, double, void*, UserDefined -#define BIG_SIZE 6 - -typedef std::tuple <BIG_TYPES> BigTuple; - - // tuple names template <class T> @@ -208,8 +181,8 @@ TYPE_NAME (TUPLE, "std::tuple<long, const char*>") #undef TUPLE -#define TUPLE std::tuple<BIG_TYPES> -// should use BIG_TYPES in string if possible +#define TUPLE \ +std::tuple<bool, char, int, double, void*, UserDefined> TYPE_NAME (TUPLE, "std::tuple<bool, char, int, double, void*, " \ "UserDefined>") Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp Fri Jul 18 11:05:55 2008 @@ -49,16 +49,22 @@ "tuple_size<" #T ">::value, got %d, expected " \ STRING (S), std::tuple_size<T>::value) - TEST (EmptyTuple, 0); + TEST (std::tuple<>, 0); - TEST (IntTuple, 1); - TEST (ConstIntTuple, 1); - TEST (UserTuple, 1); - TEST (NestedTuple, 1); + TEST (std::tuple<int>, 1); + TEST (std::tuple<const int>, 1); + TEST (std::tuple<UserDefined>, 1); + TEST (std::tuple<std::tuple<int> >, 1); - TEST (PairTuple, 2); +#undef TUPLE +#define TUPLE std::tuple<long, const char*> - TEST (BigTuple, BIG_SIZE); + TEST (TUPLE, 2); + +#undef TUPLE +#define TUPLE std::tuple<bool, char, int, double, void*, UserDefined> + + TEST (TUPLE, 6); } /**************************************************************************/ @@ -106,32 +112,43 @@ { rw_info (0, __FILE__, __LINE__, "tuple_element"); +#undef IS_SAME #define IS_SAME(T,U) \ _RW::__rw_is_same<T, U>::value + +#undef TYPE_NAME #define TYPE_NAME(T) \ (any_t (T ())).type_name () #undef TEST #define TEST(N, T, E) \ - typedef std::tuple_element<N, T>::type T ## N; \ - rw_assert (IS_SAME(T ## N, E), __FILE__, __LINE__, \ +{ \ + typedef std::tuple_element<N, T>::type elem_type; \ + rw_assert (IS_SAME(elem_type, E), __FILE__, __LINE__, \ "tuple_element<0, " #T ">::type, got type \"%s\", " \ - "expected type \"" #E "\"", TYPE_NAME (T##N)) + "expected type \"" #E "\"", TYPE_NAME (elem_type)); \ +} - TEST (0, IntTuple, int); - TEST (0, ConstIntTuple, const int); - TEST (0, NestedTuple, std::tuple<int>); - TEST (0, UserTuple, UserDefined); - - TEST (0, PairTuple, long); - TEST (1, PairTuple, const char*); - - TEST (0, BigTuple, bool); - TEST (1, BigTuple, char); - TEST (2, BigTuple, int); - TEST (3, BigTuple, double); - TEST (4, BigTuple, void*); - TEST (5, BigTuple, UserDefined); + TEST (0, std::tuple<int>, int) + TEST (0, std::tuple<const int>, const int) + TEST (0, std::tuple<std::tuple<int> >, std::tuple<int>) + TEST (0, std::tuple<UserDefined>, UserDefined) + +#undef TUPLE +#define TUPLE std::tuple<long, const char*> + + TEST (0, TUPLE, long) + TEST (1, TUPLE, const char*) + +#undef TUPLE +#define TUPLE std::tuple<bool, char, int, double, void*, UserDefined> + + TEST (0, TUPLE, bool) + TEST (1, TUPLE, char) + TEST (2, TUPLE, int) + TEST (3, TUPLE, double) + TEST (4, TUPLE, void*) + TEST (5, TUPLE, UserDefined) } /**************************************************************************/ Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.rel.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.rel.cpp?rev=677985&r1=677984&r2=677985&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/utilities/20.tuple.rel.cpp (original) +++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.rel.cpp Fri Jul 18 11:05:55 2008 @@ -43,31 +43,36 @@ { rw_info (0, __FILE__, __LINE__, "operator=="); - EmptyTuple nt1, nt2; + std::tuple<> nt1, nt2; + // special case rw_assert (nt1 == nt1, __FILE__, __LINE__, "nt1 == nt1, got false, expected true"); - rw_assert (nt1 == nt2, __FILE__, __LINE__, - "nt1 == nt2, got true, expected false"); - IntTuple it1 (1), it2 (1); - rw_assert (it1 == it1, __FILE__, __LINE__, - "it1 == it1, got false, expected true"); - rw_assert (it1 == it2, __FILE__, __LINE__, - "it1 == it2, got false, expected true"); - - UserDefined ud; - UserTuple ut1 (ud), ut2 (ud); - rw_assert (ut1 == ut1, __FILE__, __LINE__, - "ut1 == ut1, got false, expected true"); - rw_assert (ut1 == ut2, __FILE__, __LINE__, - "ut1 == ut2, got false, expected true"); - - BigTuple bt1 (true, 'a', 256, 3.14159, &nt1, ud); - BigTuple bt2 (true, 'a', 256, 3.14159, &nt1, ud); - rw_assert (bt1 == bt1, __FILE__, __LINE__, - "bt1 == bt1, got false, expected true"); - rw_assert (bt1 == bt2, __FILE__, __LINE__, - "bt1 == bt2, got false, expected true"); +#undef TEST +#define TEST(expr) \ + rw_assert (expr, __FILE__, __LINE__, #expr \ + "; got %b, expected %b", !(expr), expr) + + TEST (nt1 == nt2); + + std::tuple<int> it1 (1), it2 (1), it3 (2); + TEST (it1 == it1); + TEST (it1 == it2); + TEST (!(it1 == it3)); + + UserDefined ud1 (1), ud2 (2); + std::tuple<UserDefined> ut1 (ud1), ut2 (ud1), ut3 (ud2); + TEST (ut1 == ut1); + TEST (ut1 == ut2); + TEST (!(ut1 == ut3)); + + std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', 255, 3.14159, &nt1, ud1), + bt2 (true, 'a', 255, 3.14159, &nt1, ud1), + bt3 (true, 'a', 256, 3.14159, &nt1, ud1); + TEST (bt1 == bt1); + TEST (bt1 == bt2); + TEST (!(bt1 == bt3)); } /**************************************************************************/ @@ -77,25 +82,36 @@ { rw_info (0, __FILE__, __LINE__, "operator<"); - EmptyTuple nt1, nt2; - rw_assert (!(nt1 < nt1), __FILE__, __LINE__, - "nt1 < nt1, got true, expected false"); - rw_assert (!(nt1 < nt2), __FILE__, __LINE__, - "nt1 < nt2, got true, expected false"); - - IntTuple it1 (1), it2 (2); - rw_assert (it1 < it2, __FILE__, __LINE__, - "it1 < it2, got false, expected true"); + std::tuple<> nt1, nt2; + TEST (!(nt1 < nt1)); + TEST (!(nt1 < nt2)); + + std::tuple<int> it1 (1), it2 (2); + TEST (!(it1 < it1)); + TEST (it1 < it2); UserDefined ud1 (1), ud2 (2); - UserTuple ut1 (ud1), ut2 (ud2); - rw_assert (ut1 < ut2, __FILE__, __LINE__, - "ut1 < ut2, got false, expected true"); - - BigTuple bt1 (true, 'a', 255, 3.14159, &nt1, ud1); - BigTuple bt2 (true, 'a', 256, 3.14159, &nt1, ud1); + std::tuple<UserDefined> ut1 (ud1), ut2 (ud2); + TEST (!(ut1 < ut1)); + TEST (ut1 < ut2); + + std::tuple<long, const char*> pt1 (1234L, "string"); + TEST (!(pt1 < pt1)); + std::tuple<long, const char*> pt2 (1235L, "string"); + TEST (pt1 < pt2); + std::tuple<long, const char*> pt3 (1234L, "strings"); + TEST (pt1 < pt3); + + std::tuple<bool, char, int, double, void*, UserDefined> + bt1 (true, 'a', 255, 3.14159, &nt1, ud1), + bt2 (true, 'a', 256, 3.14159, &nt1, ud1), + bt3 (true, 'a', 255, 3.14159, &nt1, ud2); + rw_assert (!(bt1 < bt1), __FILE__, __LINE__, + "bt1 < bt1, got true, expected false"); rw_assert (bt1 < bt2, __FILE__, __LINE__, "bt1 < bt2, got false, expected true"); + rw_assert (bt1 < bt3, __FILE__, __LINE__, + "bt1 < bt3, got false, expected true"); } /**************************************************************************/