1// class template tuple -*- C++ -*- 2 3// Copyright (C) 2004, 2005 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 2, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING. If not, write to the Free 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19// USA. 20 21// As a special exception, you may use this file as part of a free software 22// library without restriction. Specifically, if other files instantiate 23// templates or use macros or inline functions from this file, or you compile 24// this file and link it with other files to produce an executable, this 25// file does not by itself cause the resulting executable to be covered by 26// the GNU General Public License. This exception does not however 27// invalidate any other reasons why the executable file might be covered by 28// the GNU General Public License. 29 30/** @file tr1/tuple 31* This is a TR1 C++ Library header. 32*/ 33 34// Chris Jefferson <chris@bubblescope.net> 35 36#ifndef _TR1_TUPLE 37#define _TR1_TUPLE 1 38 39#include <tr1/utility> 40#include <tr1/ref_fwd.h> 41 42namespace std 43{ 44_GLIBCXX_BEGIN_NAMESPACE(tr1) 45 46 // An implementation specific class which is used in the tuple class 47 // when the tuple is not maximum possible size. 48 struct _NullClass { }; 49 50 /// Gives the type of the ith element of a given tuple type. 51 template<int __i, typename _Tp> 52 struct tuple_element; 53 54 /// Finds the size of a given tuple type. 55 template<typename _Tp> 56 struct tuple_size; 57 58 // Adds a const reference to a non-reference type. 59 template<typename _Tp> 60 struct __add_c_ref 61 { typedef const _Tp& type; }; 62 63 template<typename _Tp> 64 struct __add_c_ref<_Tp&> 65 { typedef _Tp& type; }; 66 67 // Adds a reference to a non-reference type. 68 template<typename _Tp> 69 struct __add_ref 70 { typedef _Tp& type; }; 71 72 template<typename _Tp> 73 struct __add_ref<_Tp&> 74 { typedef _Tp& type; }; 75 76 // Class used in the implementation of get 77 template<int __i, typename _Tp> 78 struct __get_helper; 79 80 // Returns a const reference to the ith element of a tuple. 81 // Any const or non-const ref elements are returned with their original type. 82 83 // This class helps construct the various comparison operations on tuples 84 template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up> 85 struct __tuple_compare; 86 87 // Helper which adds a reference to a type when given a reference_wrapper 88 template<typename _Tp> 89 struct __strip_reference_wrapper 90 { 91 typedef _Tp __type; 92 }; 93 94 template<typename _Tp> 95 struct __strip_reference_wrapper<reference_wrapper<_Tp> > 96 { 97 typedef _Tp& __type; 98 }; 99 100 template<typename _Tp> 101 struct __strip_reference_wrapper<const reference_wrapper<_Tp> > 102 { 103 typedef _Tp& __type; 104 }; 105 106 #include "tuple_defs.h" 107 108 template<int __i, int __j, typename _Tp, typename _Up> 109 struct __tuple_compare<0, __i, __j, _Tp, _Up> 110 { 111 static bool __eq(const _Tp& __t, const _Up& __u) 112 { 113 return get<__i>(__t) == get<__i>(__u) && 114 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u); 115 } 116 static bool __less(const _Tp& __t, const _Up& __u) 117 { 118 return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) && 119 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u); 120 } 121 }; 122 123 template<int __i, typename _Tp, typename _Up> 124 struct __tuple_compare<0, __i, __i, _Tp, _Up> 125 { 126 static bool __eq(const _Tp&, const _Up&) 127 { return true; } 128 static bool __less(const _Tp&, const _Up&) 129 { return false; } 130 }; 131 132 // A class (and instance) which can be used in 'tie' when an element 133 // of a tuple is not required 134 struct swallow_assign 135 { 136 template<class T> 137 swallow_assign& 138 operator=(const T&) 139 { return *this; } 140 }; 141 142 // TODO: Put this in some kind of shared file. 143 namespace 144 { 145 swallow_assign ignore; 146 }; // anonymous namespace 147 148_GLIBCXX_END_NAMESPACE 149} 150 151#define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y) 152#define _GLIBCXX_CAT2(x,y) x##y 153#define _SHORT_REPEAT 154#define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h> 155#include <tr1/repeat.h> 156#undef _GLIBCXX_REPEAT_HEADER 157#undef _SHORT_REPEAT 158 159#include <tr1/functional> 160 161#endif 162