Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / tuple / cons / big_tuples.cc
blob3525bf2cb7c46675a12232c7a014aa49932d7876
1 // 2004-09-23 Chris Jefferson <chris@bubblescope.net>
3 // Copyright (C) 2004, 2005, 2006, 2007, 2008
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // Tuple
24 #include <tr1/tuple>
25 #include <testsuite_hooks.h>
27 using namespace std::tr1;
28 using std::pair;
30 // A simple class without conversions to check some things
31 struct foo
32 { };
34 void
35 test_constructors()
37 bool test __attribute__((unused)) = true;
39 int x1=0,x2=0;
40 const int &z1=x1;
42 // Test empty constructor
43 tuple<> ta __attribute__((unused));
44 tuple<int,int> tb;
45 // Test construction from values
46 tuple<int,int> tc(x1,x2);
47 tuple<int,int&> td(x1,x2);
48 tuple<const int&> te(z1);
49 x1=1;
50 x2=1;
51 VERIFY(get<0>(td) == 0 && get<1>(td) == 1 && get<0>(te) == 1);
53 // Test identical tuple copy constructor
54 tuple<int,int> tf(tc);
55 tuple<int,int> tg(td);
56 tuple<const int&> th(te);
57 // Test different tuple copy constructor
58 tuple<int,double> ti(tc);
59 tuple<int,double> tj(td);
60 // Test constructing from a pair
61 pair<int,int> pair1(1,1);
62 const pair<int,int> pair2(pair1);
63 tuple<int,int> tl(pair1);
64 tuple<int,const int&> tm(pair1);
65 tuple<int,int> tn(pair2);
66 tuple<int,const int&> to(pair2);
69 int
70 main(void)
72 //test construction
73 typedef tuple<int,int,int,int,int,int,int,int,int,int> type1;
74 type1 a(0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
75 type1 b(0, 0, 0, 0, 0, 0, 0, 0, 0, 2);
76 type1 c(a);
77 typedef tuple<int,int,int,int,int,int,int,int,int,char> type2;
78 type2 d(0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
79 type1 e(d);
80 typedef tuple<foo,int,int,int,int,int,int,int,int,foo> type3;
81 // get
82 VERIFY(get<9>(a)==1 && get<9>(b)==2);
83 // comparisons
84 VERIFY(a==a && !(a!=a) && a<=a && a>=a && !(a<a) && !(a>a));
85 VERIFY(!(a==b) && a!=b && a<=b && a<b && !(a>=b) && !(a>b));
86 //tie
88 int i = 0;
89 tie(ignore, ignore, ignore, ignore, ignore, ignore, ignore, ignore,
90 ignore, i) = a;
91 VERIFY(i == 1);
93 //test_assignment
94 a=d;
95 a=b;
96 //make_tuple
97 make_tuple(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
99 //tuple_size
100 VERIFY(tuple_size<type3>::value == 10);
101 //tuple_element
103 foo q1;
104 tuple_element<0,type3>::type q2(q1);
105 tuple_element<9,type3>::type q3(q1);