From a520f0b0aeb4f9f73b9b39bfb2923bd6c383ffb6 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Mon, 25 Oct 2004 19:05:58 +0000 Subject: [PATCH] [multiple changes] 2004-10-25 Benjamin Kosnik * include/Makefile.am (tr1_headers): Add tuple. * include/Makefile.in: Regenerate. 2004-10-25 Chris Jefferson * include/tr1/tuple: Implementation of tuple from library TR. * testsuite/tr1/6_containers/tuple/tuple_element.cc: New. * testsuite/tr1/6_containers/tuple/tuple_size.cc: New. * testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc: New. * testsuite/tr1/6_containers/tuple/cons/assignment.cc: New. * testsuite/tr1/6_containers/tuple/cons/big_tuples.cc: New. * testsuite/tr1/6_containers/tuple/cons/constructor.cc: New. * testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc: New. * testsuite/tr1/6_containers/tuple/creation_functions/tie.cc: New. * testsuite/tr1/6_containers/tuple/element_access/get.cc: New. From-SVN: r89548 --- libstdc++-v3/ChangeLog | 20 + libstdc++-v3/include/Makefile.am | 3 +- libstdc++-v3/include/Makefile.in | 3 +- libstdc++-v3/include/tr1/tuple | 1524 +++++++++++++++++ .../tuple/comparison_operators/comparisons.cc | 50 + .../tr1/6_containers/tuple/cons/assignment.cc | 53 + .../tr1/6_containers/tuple/cons/big_tuples.cc | 106 ++ .../6_containers/tuple/cons/constructor.cc | 65 + .../tuple/creation_functions/make_tuple.cc | 37 + .../tuple/creation_functions/tie.cc | 43 + .../6_containers/tuple/element_access/get.cc | 45 + .../tr1/6_containers/tuple/tuple_element.cc | 41 + .../tr1/6_containers/tuple/tuple_size.cc | 39 + 13 files changed, 2027 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/include/tr1/tuple create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/assignment.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/big_tuples.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/constructor.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/element_access/get.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_element.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_size.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 74f87faf2d1..8ef259f24ca 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2004-10-25 Benjamin Kosnik + + * include/Makefile.am (tr1_headers): Add tuple. + * include/Makefile.in: Regenerate. + +2004-10-25 Chris Jefferson + + * include/tr1/tuple: Implementation of tuple from library TR. + * testsuite/tr1/6_containers/tuple/tuple_element.cc: New. + * testsuite/tr1/6_containers/tuple/tuple_size.cc: New. + * testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc: + New. + * testsuite/tr1/6_containers/tuple/cons/assignment.cc: New. + * testsuite/tr1/6_containers/tuple/cons/big_tuples.cc: New. + * testsuite/tr1/6_containers/tuple/cons/constructor.cc: New. + * testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc: + New. + * testsuite/tr1/6_containers/tuple/creation_functions/tie.cc: New. + * testsuite/tr1/6_containers/tuple/element_access/get.cc: New. + 2004-10-25 Paolo Carlini * include/bits/basic_string.h (_Rep::_M_is_safe): Move to diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index ffa16d5aaf8..68e7641cbef 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -228,7 +228,8 @@ ext_headers = \ tr1_srcdir = ${glibcxx_srcdir}/include/tr1 tr1_builddir = ./tr1 tr1_headers = \ - ${tr1_srcdir}/array + ${tr1_srcdir}/array \ + ${tr1_srcdir}/tuple # This is the common subset of files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 4a2ec864dd8..90ddb9b9704 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -445,7 +445,8 @@ ext_headers = \ tr1_srcdir = ${glibcxx_srcdir}/include/tr1 tr1_builddir = ./tr1 tr1_headers = \ - ${tr1_srcdir}/array + ${tr1_srcdir}/array \ + ${tr1_srcdir}/tuple # This is the common subset of files that all three "C" header models use. diff --git a/libstdc++-v3/include/tr1/tuple b/libstdc++-v3/include/tr1/tuple new file mode 100644 index 00000000000..d17135ad153 --- /dev/null +++ b/libstdc++-v3/include/tr1/tuple @@ -0,0 +1,1524 @@ +// class template tuple -*- C++ -*- + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Chris Jefferson + +// This header is automatically generated: see maketuple.c for details. + +#ifndef _TUPLE +#define _TUPLE 1 + +#include + +namespace std +{ +namespace tr1 +{ + // An implementation specific class which is used in the tuple class + // when the tuple is not maximum possible size. + struct _NullClass { }; + + // Foward definition of the tuple class + template + class tuple; + + // Gives the type of the ith element of a given tuple type. + template + struct tuple_element; + + template + struct tuple_element<0, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T0 type; }; + + template + struct tuple_element<1, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T1 type; }; + + template + struct tuple_element<2, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T2 type; }; + + template + struct tuple_element<3, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T3 type; }; + + template + struct tuple_element<4, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T4 type; }; + + template + struct tuple_element<5, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T5 type; }; + + template + struct tuple_element<6, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T6 type; }; + + template + struct tuple_element<7, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T7 type; }; + + template + struct tuple_element<8, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T8 type; }; + + template + struct tuple_element<9, tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> > + { typedef _T9 type; }; + + // Finds the size of a given tuple type. + // NB: Can't this be done via value->type conversions in the generic + // tuple class, say with an enum? + template + struct tuple_size; + + template<> + struct tuple_size > + { static const int value = 0; }; + + template + struct tuple_size > + { static const int value = 1; }; + + template + struct tuple_size > + { static const int value = 2; }; + + template + struct tuple_size > + { static const int value = 3; }; + + template + struct tuple_size > + { static const int value = 4; }; + + template + struct tuple_size > + { static const int value = 5; }; + + template + struct tuple_size > + { static const int value = 6; }; + + template + struct tuple_size > + { static const int value = 7; }; + + template + struct tuple_size > + { static const int value = 8; }; + + template + struct tuple_size > + { static const int value = 9; }; + + template + struct tuple_size > + { static const int value = 10; }; + + // Adds a const reference to a non-reference type. + template + struct __add_const_ref + { typedef const _T& type; }; + + template + struct __add_const_ref<_T&> + { typedef _T& type; }; + + // Adds a reference to a non-reference type. + template + struct __add_ref + { typedef _T& type; }; + + template + struct __add_ref<_T&> + { typedef _T& type; }; + + // The empty tuple. + template<> + class tuple<_NullClass, _NullClass, _NullClass, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass, _NullClass, _NullClass> + { + public: + tuple() + { } + + tuple(const tuple& __in) + { } + + tuple& operator=(const tuple& __in) + { return *this; } + }; + + template + class tuple<_T0, _NullClass, _NullClass, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass, _NullClass, _NullClass> + { + _T0 __t0; + + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0): + __t0(__in0) + { } + + tuple(const tuple& __in): + __t0(__in.__t0) + { } + template + tuple(const tuple<_U0>& __in): + __t0(__in.__t0) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + return *this; + } + + template + tuple& + operator=(const tuple<_U0>& __in) + { + __t0=__in.__t0; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _NullClass, _NullClass, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1): + __t0(__in0), __t1(__in1) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1) + { } + template + tuple(const tuple<_U0, _U1>& __in): + __t0(__in.__t0), __t1(__in.__t1) + { } + + template + tuple(const std::pair<_U1, _U2>& __u): __t0(__u.first), __t1(__u.second) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _NullClass, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2): + __t0(__in0), __t1(__in1), __t2(__in2) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2) + { } + template + tuple(const tuple<_U0, _U1, _U2>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _NullClass, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _T4, _NullClass, _NullClass, + _NullClass, _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _T4, _T5, _NullClass, _NullClass, + _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + _T5 __t5; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4, + typename __add_const_ref<_T5>::type __in5): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4), __t5(__in5) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4, _U5>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4, _U5>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _NullClass, + _NullClass, _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + _T5 __t5; + _T6 __t6; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4, + typename __add_const_ref<_T5>::type __in5, + typename __add_const_ref<_T6>::type __in6): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4), __t5(__in5), __t6(__in6) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _NullClass, + _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + _T5 __t5; + _T6 __t6; + _T7 __t7; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4, + typename __add_const_ref<_T5>::type __in5, + typename __add_const_ref<_T6>::type __in6, + typename __add_const_ref<_T7>::type __in7): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4), __t5(__in5), __t6(__in6), __t7(__in7) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7 + >& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7 + >& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _NullClass> + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + _T5 __t5; + _T6 __t6; + _T7 __t7; + _T8 __t8; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4, + typename __add_const_ref<_T5>::type __in5, + typename __add_const_ref<_T6>::type __in6, + typename __add_const_ref<_T7>::type __in7, + typename __add_const_ref<_T8>::type __in8): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4), __t5(__in5), __t6(__in6), __t7(__in7), + __t8(__in8) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7), __t8(__in.__t8) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8 + >& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7), __t8(__in.__t8) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + __t8=__in.__t8; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, + _U8>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + __t8=__in.__t8; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + template + class tuple + { + _T0 __t0; + _T1 __t1; + _T2 __t2; + _T3 __t3; + _T4 __t4; + _T5 __t5; + _T6 __t6; + _T7 __t7; + _T8 __t8; + _T9 __t9; + public: + tuple() + { } + + explicit tuple(typename __add_const_ref<_T0>::type __in0, + typename __add_const_ref<_T1>::type __in1, + typename __add_const_ref<_T2>::type __in2, + typename __add_const_ref<_T3>::type __in3, + typename __add_const_ref<_T4>::type __in4, + typename __add_const_ref<_T5>::type __in5, + typename __add_const_ref<_T6>::type __in6, + typename __add_const_ref<_T7>::type __in7, + typename __add_const_ref<_T8>::type __in8, + typename __add_const_ref<_T9>::type __in9): + __t0(__in0), __t1(__in1), __t2(__in2), __t3(__in3), + __t4(__in4), __t5(__in5), __t6(__in6), __t7(__in7), + __t8(__in8), __t9(__in9) + { } + + tuple(const tuple& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7), __t8(__in.__t8), + __t9(__in.__t9) + { } + template + tuple(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, + _U9>& __in): + __t0(__in.__t0), __t1(__in.__t1), __t2(__in.__t2), + __t3(__in.__t3), __t4(__in.__t4), __t5(__in.__t5), + __t6(__in.__t6), __t7(__in.__t7), __t8(__in.__t8), + __t9(__in.__t9) + { } + + tuple& operator=(const tuple& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + __t8=__in.__t8; + __t9=__in.__t9; + return *this; + } + + template + tuple& + operator=(const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, + _U8, _U9>& __in) + { + __t0=__in.__t0; + __t1=__in.__t1; + __t2=__in.__t2; + __t3=__in.__t3; + __t4=__in.__t4; + __t5=__in.__t5; + __t6=__in.__t6; + __t7=__in.__t7; + __t8=__in.__t8; + __t9=__in.__t9; + return *this; + } + template + friend class __get_helper; + template + friend class tuple; + }; + + // Class used in the implementation of get + template + struct __get_helper; + + template + struct __get_helper<0, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { return __in.__t0; } + + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { return __in.__t0; } + }; + + template + struct __get_helper<1, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t1; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t1; + } + }; + + template + struct __get_helper<2, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t2; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t2; + } + }; + + template + struct __get_helper<3, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t3; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t3; + } + }; + + template + struct __get_helper<4, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t4; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t4; + } + }; + + template + struct __get_helper<5, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t5; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t5; + } + }; + + template + struct __get_helper<6, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t6; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t6; + } + }; + + template + struct __get_helper<7, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t7; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t7; + } + }; + + template + struct __get_helper<8, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t8; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t8; + } + }; + + template + struct __get_helper<9, _T> + { + static typename __add_ref::type>::type + get_value(_T& __in) + { + return __in.__t9; + } + static typename __add_const_ref::type>::type + get_value(const _T& __in) + { + return __in.__t9; + } + }; + + /* Returns a reference to the ith element of a tuple. + * Any const or non-const ref elements are returned with their original type + */ + template + typename __add_ref >::type>::type + get(tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9>& __t) + { + return __get_helper<__i,tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> >::get_value(__t); + } + + /* Returns a const reference to the ith element of a tuple. + * Any const or non-const ref elements are returned with their original type + */ + template + typename __add_const_ref >::type>::type + get(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + >& __t) + { + return __get_helper<__i,tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, + _T7, _T8, _T9> >::get_value(__t); + } + + // This class helps construct the various comparison operations on tuples + template + struct __tuple_compare; + + template + struct __tuple_compare<0, __i, __j, _T, _U> + { + static bool __eq(const _T& __t, const _U& __u) + { + return get<__i>(__t) == get<__i>(__u) && + __tuple_compare<0, __i+1, __j, _T, _U>::__eq(__t, __u) ; + } + static bool __neq(const _T& __t, const _U& __u) + { + return get<__i>(__t) != get<__i>(__u) || + __tuple_compare<0, __i+1, __j, _T, _U>::__neq(__t, __u) ; + } + static bool __less(const _T& __t, const _U& __u) + { + return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) && + __tuple_compare<0, __i+1, __j, _T, _U>::__less(__t, __u) ; + } + static bool __greater(const _T& __t, const _U& __u) + { + return (get<__i>(__t) > get<__i>(__u)) || !(get<__i>(__u) > get<__i>(__t)) && + __tuple_compare<0, __i+1, __j, _T, _U>::__greater(__t, __u) ; + } + static bool __leq(const _T& __t, const _U& __u) + { + return (get<__i>(__t) <= get<__i>(__u)) && (!(get<__i>(__u)<=get<__i>(__t)) || + __tuple_compare<0, __i+1, __j, _T, _U>::__leq(__t, __u) ); + } + static bool __geq(const _T& __t, const _U& __u) + { + return (get<__i>(__t) >= get<__i>(__u)) && (!(get<__i>(__u)>=get<__i>(__t)) || + __tuple_compare<0, __i+1, __j, _T, _U>::__geq(__t, __u) ); + } + }; + + template + struct __tuple_compare<0, __i, __i, _T, _U> + { + static bool __eq(const _T&, const _U&) + { + return true; + } + static bool __neq(const _T&, const _U&) + { + return false; + } + static bool __leq(const _T&, const _U&) + { + return true; + } + static bool __geq(const _T&, const _U&) + { + return true; + } + static bool __less(const _T&, const _U&) + { + return false; + } + static bool __greater(const _T&, const _U&) + { + return false; + } + }; + + template + bool + operator==(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__eq(__t, __u); + } + + template + bool + operator!=(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__neq(__t, __u); + } + + template + bool + operator<(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__less(__t, __u); + } + + template + bool + operator>(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__greater(__t, __u); + } + + template + bool + operator<=(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__leq(__t, __u); + } + + template + bool + operator>=(const tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, + _T9>& __t, const tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, + _U7, _U8, _U9>& __u) + { + typedef tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 + > __T_tuple; + typedef tuple<_U0, _U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9 + > __U_tuple; + return __tuple_compare::value - + tuple_size<__U_tuple>::value, 0, + tuple_size<__T_tuple>::value, __T_tuple, __U_tuple>::__geq(__t, __u); + } + + // Provides a way to annotate that a reference to + // an object should be passed. + template + class reference_wrapper + { + _T& __data; + + public: + typedef _T type; + + explicit reference_wrapper(_T& __indata): __data(__indata) + { } + + operator _T&() const + { return this->get(); } + + _T& + get() const + { return __data; } + }; + + // Denotes a reference should be taken to a variable. + template + reference_wrapper<_T> + ref(_T& __t) + { return reference_wrapper<_T>(__t); } + + // Denotes a const reference should be taken to a variable. + template + reference_wrapper<_T const> + cref(const _T& __t) + { return reference_wrapper<_T const>(__t); } + + // Helper which adds a reference to a type when given a reference_wrapper + template + struct __strip_reference_wrapper + { typedef _T __type; }; + + template + struct __strip_reference_wrapper > + { typedef _T& __type; }; + + template + struct __strip_reference_wrapper > + { typedef _T& __type; }; + + template + struct __stripped_tuple_type + { + typedef tuple::__type, + typename __strip_reference_wrapper<_T1>::__type, + typename __strip_reference_wrapper<_T2>::__type, + typename __strip_reference_wrapper<_T3>::__type, + typename __strip_reference_wrapper<_T4>::__type, + typename __strip_reference_wrapper<_T5>::__type, + typename __strip_reference_wrapper<_T6>::__type, + typename __strip_reference_wrapper<_T7>::__type, + typename __strip_reference_wrapper<_T8>::__type, + typename __strip_reference_wrapper<_T9>::__type> __type; + }; + + tuple<> + make_tuple() + { + return tuple<>(); + }; + + template + typename __stripped_tuple_type<_T0>::__type + make_tuple(_T0 __t0) + { + return typename __stripped_tuple_type<_T0>::__type(__t0);}; + + template + typename __stripped_tuple_type<_T0, _T1>::__type + make_tuple(_T0 __t0, _T1 __t1) + { + return typename __stripped_tuple_type<_T0, _T1>::__type(__t0, __t1);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2) + { + return typename __stripped_tuple_type<_T0, _T1, _T2>::__type(__t0, __t1, __t2);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3>::__type(__t0, __t1, __t2, __t3);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4>::__type(__t0, __t1, __t2, __t3, __t4);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4, + _T5 __t5) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5 + >::__type(__t0, __t1, __t2, __t3, __t4, __t5);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, _T6 + >::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4, + _T5 __t5, _T6 __t6) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, + _T6>::__type(__t0, __t1, __t2, __t3, __t4, __t5, __t6);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7 + >::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4, + _T5 __t5, _T6 __t6, _T7 __t7) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, + _T6, _T7>::__type(__t0, __t1, __t2, __t3, __t4, __t5, __t6, __t7);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, + _T8>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4, + _T5 __t5, _T6 __t6, _T7 __t7, _T8 __t8) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, + _T6, _T7, _T8>::__type(__t0, __t1, __t2, __t3, __t4, __t5, __t6, __t7, __t8);}; + + template + typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, + _T8, _T9>::__type + make_tuple(_T0 __t0, _T1 __t1, _T2 __t2, _T3 __t3, _T4 __t4, + _T5 __t5, _T6 __t6, _T7 __t7, _T8 __t8, _T9 __t9) + { + return typename __stripped_tuple_type<_T0, _T1, _T2, _T3, _T4, _T5, + _T6, _T7, _T8, _T9>::__type(__t0, __t1, __t2, __t3, __t4, __t5, __t6, __t7, __t8, __t9 + );}; + + // A class (and instance) which can be used in 'tie' when a element + // is not required. + struct swallow_assign + { + template + swallow_assign& + operator=(const T&) + { return *this; } + }; + + // TODO: Put this in some kind of shared file + namespace + { + swallow_assign ignore; + }; + + // extern swallow_assign ignore; + + + // Allows forms a tuple of references to a list of variables. + template + tuple<_T0&> + tie(_T0& __t0) + { return make_tuple(ref(__t0)); }; + + template + tuple<_T0&, _T1&> + tie(_T0& __t0, _T1& __t1) + { return make_tuple(ref(__t0), ref(__t1)); }; + + template + tuple<_T0&, _T1&, _T2&> + tie(_T0& __t0, _T1& __t1, _T2& __t2) + { return make_tuple(ref(__t0), ref(__t1), ref(__t2)); }; + + template + tuple<_T0&, _T1&, _T2&, _T3&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3) + { return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3)); }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), ref(__t4)); + }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&, _T5&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4, _T5& __t5) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), + ref(__t4), ref(__t5)); + }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&, _T5&, _T6&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4, + _T5& __t5, _T6& __t6) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), + ref(__t4), ref(__t5), ref(__t6)); + }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&, _T5&, _T6&, _T7&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4, + _T5& __t5, _T6& __t6, _T7& __t7) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), + ref(__t4), ref(__t5), ref(__t6), ref(__t7)); + }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&, _T5&, _T6&, _T7&, _T8&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4, + _T5& __t5, _T6& __t6, _T7& __t7, _T8& __t8) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), + ref(__t4), ref(__t5), ref(__t6), ref(__t7), ref(__t8)); + }; + + template + tuple<_T0&, _T1&, _T2&, _T3&, _T4&, _T5&, _T6&, _T7&, _T8&, _T9&> + tie(_T0& __t0, _T1& __t1, _T2& __t2, _T3& __t3, _T4& __t4, + _T5& __t5, _T6& __t6, _T7& __t7, _T8& __t8, _T9& __t9) + { + return make_tuple(ref(__t0), ref(__t1), ref(__t2), ref(__t3), + ref(__t4), ref(__t5), ref(__t6), ref(__t7), ref(__t8), + ref(__t9)); + }; + + // Various functions which give std::pair a tuple-like interface. + template + struct tuple_size > + { static const int value = 2; }; + + template + struct tuple_element<0, std::pair<_T1, _T2> > + { typedef _T1 type; }; + + template + struct tuple_element<1, std::pair<_T1, _T2> > + { typedef _T2 type; }; + + template + typename tuple_element<_I, tuple<_T1, _T2> >::type + get(pair<_T1, _T2>& __in) + { return get<_I>(tie(__in.first, __in.second)); } + + template + typename tuple_element<_I, tuple<_T1, _T2> >::type + get(const pair<_T1, _T2>& __in) + { return get<_I>(tie(__in.first, __in.second)); } +} +} + +#endif diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc new file mode 100644 index 00000000000..ed3ad656c76 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/comparison_operators/comparisons.cc @@ -0,0 +1,50 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +#define TEST1(x) VERIFY( x == x && !(x != x) && x <= x && !(x < x) ) + +int +main() +{ + int i=0; + int j=0; + int k=2; + tuple a(0, 0, 0); + tuple b(0, 0, 1); + tuple c(i,j,k); + tuple d(c); + TEST1(a); + TEST1(b); + TEST1(c); + TEST1(d); + VERIFY(!(a > a) && !(b > b)); + VERIFY(a >= a && b >= b); + VERIFY(a < b && !(b < a) && a <= b && !(b <= a)); + VERIFY(b > a && !(a > b) && b >= a && !(a >= b)); +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/assignment.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/assignment.cc new file mode 100644 index 00000000000..3723e59fd40 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/assignment.cc @@ -0,0 +1,53 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + tuple<> ta; + tuple<> tb; + ta = tb; + + tuple tc(1); + tuple td(0); + td = tc; + VERIFY(get<0>(td) == 1); + + int i=0; + tuple te(i); + te = tc; + VERIFY(i == 1); + + tuple tf(tc); + + get<0>(tc) = 2; + VERIFY(get<0>(tf) == 2); + tuple tg; + tg = tc; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/big_tuples.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/big_tuples.cc new file mode 100644 index 00000000000..860a354e542 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/big_tuples.cc @@ -0,0 +1,106 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +// A simple class without conversions to check some things +struct foo +{ }; + +void +test_constructors() +{ + int x1=0,x2=0; + const int &z1=x1; + + // Test empty constructor + tuple<> ta; + tuple tb; + // Test construction from values + tuple tc(x1,x2); + tuple td(x1,x2); + tuple te(z1); + x1=1; + x2=1; + VERIFY(get<0>(td) == 0 && get<1>(td) == 1 && get<0>(te) == 1); + + // Test identical tuple copy constructor + tuple tf(tc); + tuple tg(td); + tuple th(te); + // Test different tuple copy constructor + tuple ti(tc); + tuple tj(td); + // Test constructing from a pair + pair pair1(1,1); + const pair pair2(pair1); + tuple tl(pair1); + tuple tm(pair1); + tuple tn(pair2); + tuple to(pair2); +} + +int +main(void) +{ + //test construction + typedef tuple type1; + type1 a(0, 0, 0, 0, 0, 0, 0, 0, 0, 1); + type1 b(0, 0, 0, 0, 0, 0, 0, 0, 0, 2); + type1 c(a); + typedef tuple type2; + type2 d(0, 0, 0, 0, 0, 0, 0, 0, 0, 3); + type1 e(d); + typedef tuple type3; + // get + VERIFY(get<9>(a)==1 && get<9>(b)==2); + // comparisons + VERIFY(a==a && !(a!=a) && a<=a && a>=a && !(aa)); + VERIFY(!(a==b) && a!=b && a<=b && a=b) && !(a>b)); + //tie + { + int i = 0; + tie(ignore, ignore, ignore, ignore, ignore, ignore, ignore, ignore, + ignore, i) = a; + VERIFY(i == 1); + } + //test_assignment + a=d; + a=b; + //make_tuple + make_tuple(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + //tuple_size + VERIFY(tuple_size::value == 10); + //tuple_element + { + foo q1; + tuple_element<0,type3>::type q2(q1); + tuple_element<9,type3>::type q3(q1); + } + +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/constructor.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/constructor.cc new file mode 100644 index 00000000000..f3efc53953c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/cons/constructor.cc @@ -0,0 +1,65 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + int x1=0,x2=0; + const int &z1=x1; + + // Test empty constructor + tuple<> ta; + tuple tb; + // Test construction from values + tuple tc(x1,x2); + tuple td(x1,x2); + tuple te(z1); + x1=1; + x2=1; + VERIFY(get<0>(td) == 0 && get<1>(td) == 1 && get<0>(te) == 1); + + // Test identical tuple copy constructor + tuple tf(tc); + tuple tg(td); + tuple th(te); + // Test different tuple copy constructor + tuple ti(tc); + tuple tj(td); + //tuple tk(tc); + tuple tl(tc); + tuple tm(tl); + // Test constructing from a pair + pair pair1(1,1); + const pair pair2(pair1); + tuple tn(pair1); + tuple to(pair1); + tuple tp(pair2); + tuple tq(pair2); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc new file mode 100644 index 00000000000..67b69f55f35 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/make_tuple.cc @@ -0,0 +1,37 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + int i=0; + make_tuple(1,2,4.0); + make_tuple(ref(i)) = tuple(1); + VERIFY(i == 1); +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie.cc new file mode 100644 index 00000000000..4de95672741 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie.cc @@ -0,0 +1,43 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + int x1 = 0; + int x2 = 0; + int y1 = 0; + int y2 = 0; + tuple ta(1,1); + tuple tc(x1,x2); + tie(y1,y2)=ta; + VERIFY(y1 == 1 && y2 == 1); + tie(y1,y2)=tc; + VERIFY(y1 == 0 && y2 == 0); +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/element_access/get.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/element_access/get.cc new file mode 100644 index 00000000000..83ff17c44f4 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/element_access/get.cc @@ -0,0 +1,45 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + int j=1; + const int k=2; + tuple a(0,j,k); + const tuple b(1,j,k); + VERIFY(get<0>(a)==0 && get<1>(a)==1 && get<2>(a)==2); + get<0>(a)=3; + get<1>(a)=4; + VERIFY(get<0>(a)==3 && get<1>(a)==4); + VERIFY(j==4); + get<1>(b)=5; + VERIFY(get<0>(b)==1 && get<1>(b)==5 && get<2>(b)==2); + VERIFY(j==5); +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_element.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_element.cc new file mode 100644 index 00000000000..8a8b6305e1a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_element.cc @@ -0,0 +1,41 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +struct foo +{ }; + +int +main() +{ + // As foo isn't constructable from anything else, this + // lets us check if type is returning foo when it should + foo q1; + tuple_element<0,tuple >::type q2(q1); + tuple_element<2,tuple >::type q3(q1); +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_size.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_size.cc new file mode 100644 index 00000000000..eb6c427b2e6 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/tuple_size.cc @@ -0,0 +1,39 @@ +// 2004-09-23 Chris Jefferson + +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// Tuple + +#include +#include + +using namespace std; +using namespace tr1; + +int +main() +{ + VERIFY(tuple_size >::value == 0); + VERIFY(tuple_size >::value == 1); + VERIFY(tuple_size >::value == 1); + typedef tuple test_tuple1; + VERIFY(tuple_size::value == 3); + VERIFY(tuple_size > >::value == 1); +} + -- 2.30.2