// class template tuple -*- C++ -*- // Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file * This is a TR1 C++ Library header. */ // Chris Jefferson #ifndef _TUPLE #define _TUPLE 1 #include #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 { }; template class tuple; /// Gives the type of the ith element of a given tuple type. template struct tuple_element; /// Finds the size of a given tuple type. template struct tuple_size; // Adds a const reference to a non-reference type. template struct __add_c_ref { typedef const _Tp& type; }; template struct __add_c_ref<_Tp&> { typedef _Tp& type; }; // Adds a reference to a non-reference type. template struct __add_ref { typedef _Tp& type; }; template struct __add_ref<_Tp&> { typedef _Tp& type; }; // Class used in the implementation of get template struct __get_helper; // 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_ref >::type>::type get(tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t) { return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9> >::get_value(__t); } template typename __add_c_ref >::type>::type get(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t) { return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9> >::get_value(__t); } // This class helps construct the various comparison operations on tuples template struct __tuple_compare; template struct __tuple_compare<0, __i, __j, _Tp, _Up> { static bool __eq(const _Tp& __t, const _Up& __u) { return get<__i>(__t) == get<__i>(__u) && __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u); } static bool __less(const _Tp& __t, const _Up& __u) { return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) && __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u); } }; template struct __tuple_compare<0, __i, __i, _Tp, _Up> { static bool __eq(const _Tp&, const _Up&) { return true; } static bool __less(const _Tp&, const _Up&) { return false; } }; template bool operator==(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp; typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up; return __tuple_compare::value - tuple_size<_Tp>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u); } template bool operator<(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp; typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up; return __tuple_compare::value - tuple_size<_Tp>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u); } template bool operator!=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { return !(__t == __u); } template bool operator>(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { return __u < __t; } template bool operator<=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { return !(__u < __t); } template bool operator>=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t, const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u) { return !(__t < __u); } // Helper which adds a reference to a type when given a reference_wrapper template struct __strip_reference_wrapper { typedef _Tp __type; }; template struct __strip_reference_wrapper > { typedef _Tp& __type; }; template struct __strip_reference_wrapper > { typedef _Tp& __type; }; template struct __stripped_tuple_type { typedef tuple::__type, typename __strip_reference_wrapper<_Tp1>::__type, typename __strip_reference_wrapper<_Tp2>::__type, typename __strip_reference_wrapper<_Tp3>::__type, typename __strip_reference_wrapper<_Tp4>::__type, typename __strip_reference_wrapper<_Tp5>::__type, typename __strip_reference_wrapper<_Tp6>::__type, typename __strip_reference_wrapper<_Tp7>::__type, typename __strip_reference_wrapper<_Tp8>::__type, typename __strip_reference_wrapper<_Tp9>::__type> __type; }; // A class (and instance) which can be used in 'tie' when an element // of a tuple 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; }; #define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y) #define _GLIBCXX_CAT2(x,y) x##y #define _SHORT_REPEAT #define _GLIBCXX_REPEAT_HEADER #include #undef _GLIBCXX_REPEAT_HEADER #undef _SHORT_REPEAT } } #include #endif