Dune Core Modules (2.4.1)

tuples.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_TUPLES_HH
5#define DUNE_TUPLES_HH
6
7#include <iostream>
8
9#include "typetraits.hh"
10#include "unused.hh"
11
12#include <tuple>
13
14namespace Dune {
33 template<class T>
34 struct TupleAccessTraits
35 {
36 typedef typename ConstantVolatileTraits<T>::ConstType& ConstType;
37 typedef T& NonConstType;
38 typedef const typename ConstantVolatileTraits<T>::UnqualifiedType& ParameterType;
39 };
40
41 template<class T>
42 struct TupleAccessTraits<T*>
43 {
44 typedef typename ConstantVolatileTraits<T>::ConstType* ConstType;
45 typedef T* NonConstType;
46 typedef T* ParameterType;
47 };
48
49 template<class T>
50 struct TupleAccessTraits<T&>
51 {
52 typedef T& ConstType;
53 typedef T& NonConstType;
54 typedef T& ParameterType;
55 };
56
57 // pull in default implementations
58 using std::tuple;
59 using std::tuple_element;
60 using std::get;
61 using std::tuple_size;
62 using std::tie;
63 using std::make_tuple;
64
65
66 template<int i>
67 struct tuple_writer
68 {
69 template<class T>
70 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
71 {
72 return tuple_writer<i-1>::put(os,t,delim)<<delim<<Dune::get<i-1>(t);
73 }
74
75 template< class T >
76 static std::istream &get ( std::istream &is, T &t, const char *delim = "," )
77 {
78 tuple_writer< i-1 >::get( is, t, delim );
79 for( const char *it = delim; is && (*it != 0); ++it )
80 {
81 char c = 0;
82 is >> c;
83 if( c != *it )
84 is.setstate( std::ios::failbit );
85 }
86 return is >> Dune::get< i-1 >( t );
87 }
88 };
89
90 template<>
91 struct tuple_writer<1>
92 {
93 template<class T>
94 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
95 {
97 return os<<Dune::get<0>(t);
98 }
99
100 template< class T >
101 static std::istream &get ( std::istream &is, T &t, const char *delim = ", " )
102 {
103 return is >> Dune::get< 0 >( t );
104 }
105 };
106
107 template<>
108 struct tuple_writer<0>
109 {
110 template<class T>
111 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
112 {
113 return os;
114 }
115
116 template< class T >
117 static std::istream &get ( std::istream &is, T &t, const char *delim = ", " )
118 {
119 return is;
120 }
121 };
122
126 template<typename T1>
127 inline std::ostream& operator<<( std::ostream& os, const tuple<T1> & t)
128 {
129 typedef tuple<T1> TupleT;
130 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
131 }
132
133 template<typename T1, typename T2>
134 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2> & t)
135 {
136 typedef tuple<T1,T2> TupleT;
137 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
138 }
139
140 template<typename T1, typename T2, typename T3>
141 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3> & t)
142 {
143 typedef tuple<T1,T2,T3> TupleT;
144 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
145 }
146
147 template<typename T1, typename T2, typename T3, typename T4>
148 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4> & t)
149 {
150 typedef tuple<T1,T2,T3,T4> TupleT;
151 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
152 }
153
154 template<typename T1, typename T2, typename T3, typename T4, typename T5>
155 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5> & t)
156 {
157 typedef tuple<T1,T2,T3,T4,T5> TupleT;
158 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
159 }
160
161 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
162 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6> & t)
163 {
164 typedef tuple<T1,T2,T3,T4,T5,T6> TupleT;
165 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
166 }
167
168 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
169 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7> & t)
170 {
171 typedef tuple<T1,T2,T3,T4,T5,T6,T7> TupleT;
172 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
173 }
174
175 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
176 typename T8>
177 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8> & t)
178 {
179 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8> TupleT;
180 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
181 }
182
183 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
184 typename T8, typename T9>
185 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> & t)
186 {
187 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> TupleT;
188 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
189 }
190
191 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
192 typename T8, typename T9, typename T10>
193 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> & t)
194 {
195 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> TupleT;
196 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
197 }
198
202 template<typename T1>
203 inline std::istream& operator>>( std::istream& is, tuple<T1> & t)
204 {
205 typedef tuple<T1> TupleT;
206 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
207 }
208
209 template<typename T1, typename T2>
210 inline std::istream& operator>>( std::istream& is, tuple<T1,T2> & t)
211 {
212 typedef tuple<T1,T2> TupleT;
213 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
214 }
215
216 template<typename T1, typename T2, typename T3>
217 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3> & t)
218 {
219 typedef tuple<T1,T2,T3> TupleT;
220 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
221 }
222
223 template<typename T1, typename T2, typename T3, typename T4>
224 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4> & t)
225 {
226 typedef tuple<T1,T2,T3,T4> TupleT;
227 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
228 }
229
230 template<typename T1, typename T2, typename T3, typename T4, typename T5>
231 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5> & t)
232 {
233 typedef tuple<T1,T2,T3,T4,T5> TupleT;
234 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
235 }
236
237 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
238 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6> & t)
239 {
240 typedef tuple<T1,T2,T3,T4,T5,T6> TupleT;
241 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
242 }
243
244 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
245 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7> & t)
246 {
247 typedef tuple<T1,T2,T3,T4,T5,T6,T7> TupleT;
248 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
249 }
250
251 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
252 typename T8>
253 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8> & t)
254 {
255 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8> TupleT;
256 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
257 }
258
259 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
260 typename T8, typename T9>
261 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> & t)
262 {
263 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> TupleT;
264 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
265 }
266
267 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
268 typename T8, typename T9, typename T10>
269 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> & t)
270 {
271 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> TupleT;
272 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
273 }
274
276}
277#endif
std::istream & operator>>(std::istream &is, tuple< T1 > &t)
Read a tuple.
Definition: tuples.hh:203
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:26
Dune namespace.
Definition: alignment.hh:10
T UnqualifiedType
The unqualified type.
Definition: typetraits.hh:90
const T ConstType
The const type.
Definition: typetraits.hh:92
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)