Dune Core Modules (2.3.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 "static_assert.hh"
11#include "unused.hh"
12
13#ifdef HAVE_TUPLE
14#include <tuple>
15#elif defined HAVE_TR1_TUPLE
16#include <tr1/tuple>
17#endif
18
19namespace Dune {
38 template<class T>
39 struct TupleAccessTraits
40 {
41 typedef typename ConstantVolatileTraits<T>::ConstType& ConstType;
42 typedef T& NonConstType;
43 typedef const typename ConstantVolatileTraits<T>::UnqualifiedType& ParameterType;
44 };
45
46 template<class T>
47 struct TupleAccessTraits<T*>
48 {
49 typedef typename ConstantVolatileTraits<T>::ConstType* ConstType;
50 typedef T* NonConstType;
51 typedef T* ParameterType;
52 };
53
54 template<class T>
55 struct TupleAccessTraits<T&>
56 {
57 typedef T& ConstType;
58 typedef T& NonConstType;
59 typedef T& ParameterType;
60 };
61
62#ifdef HAVE_TUPLE
63 using std::tuple;
64#elif defined HAVE_TR1_TUPLE
65 using std::tr1::tuple;
66#else
70 struct Nil
71 {};
72
73 namespace
74 {
75 inline const Nil nullType()
76 {
77 return Nil();
78 }
79 }
80
86 template<typename T1, typename TT>
87 struct Pair
88 {
92 typedef T1 Type1;
93
97 typedef TT Type2;
98 // enum{
99 // /**
100 // * @brief The number of values we hold.
101 // */
102 // values = 2;
103 // };
104
118 template<typename T2, typename T3, typename T4, typename T5,
119 typename T6, typename T7, typename T8, typename T9>
120 Pair(typename TupleAccessTraits<T1>::ParameterType t1, T2& t2, T3& t3, T4& t4, T5& t5,
121 T6& t6, T7& t7, T8& t8, T9& t9);
122
129 Pair(typename TupleAccessTraits<Type1>::ParameterType t1, TT& t2);
130
131 Pair();
132
137 template<typename U1, typename U2>
138 Pair(const Pair<U1,U2>& other);
139
144 template<typename U1, typename U2>
145 Pair& operator=(const Pair<U1,U2>& other);
146
147 Pair& operator=(const Pair& other);
148
153 typename TupleAccessTraits<Type1>::NonConstType first();
154
159 typename TupleAccessTraits<Type1>::ConstType
160 first() const;
161
166 typename TupleAccessTraits<Type2>::NonConstType
167 second();
168
173 typename TupleAccessTraits<Type2>::ConstType
174 second() const;
175
180
181 };
182
187 template<typename T1>
188 struct Pair<T1,Nil>
189 {
193 typedef T1 Type1;
194
200 typedef Nil Type2;
201
206 Pair(typename TupleAccessTraits<T1>::ParameterType first, const Nil&, const Nil&, const Nil&, const Nil&,
207 const Nil&, const Nil&, const Nil&, const Nil&);
208
213 Pair(typename TupleAccessTraits<T1>::ParameterType first,
214 const Nil&);
215
216 Pair();
217
221 template<typename T2>
222 Pair(const Pair<T2,Nil>& other);
223
227 template<typename T2>
229
233 Pair& operator=(const Pair& other);
234
239 typename TupleAccessTraits<Type1>::NonConstType
240 first();
241
246 typename TupleAccessTraits<Type1>::ConstType
247 first() const;
248
251 };
252
253
257 template<typename T1, typename T2, typename T3, typename T4, typename T5,
258 typename T6, typename T7, typename T8, typename T9>
260 {
262 };
263
267 template<typename T1>
269 {
270 typedef Pair<T1,Nil> Type;
271 };
272
290 template<typename T1 = Nil, typename T2 = Nil, typename T3 = Nil,
291 typename T4 = Nil, typename T5 = Nil,typename T6 = Nil,
292 typename T7 = Nil, typename T8 = Nil, typename T9 = Nil>
293 class tuple : public TupleToPairs<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Type
294 {
295 public:
298
299 tuple()
300 {}
301
302 tuple(typename TupleAccessTraits<T1>::ParameterType t1)
303 : FirstPair(t1, nullType(), nullType(), nullType(),
304 nullType(), nullType(), nullType(), nullType(),
305 nullType())
306 {}
307
308 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
309 typename TupleAccessTraits<T2>::ParameterType t2)
310 : FirstPair(t1, t2, nullType(), nullType(),
311 nullType(), nullType(), nullType(), nullType(),
312 nullType())
313 {}
314
315 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
316 typename TupleAccessTraits<T2>::ParameterType t2,
317 typename TupleAccessTraits<T3>::ParameterType t3)
318 : FirstPair(t1, t2, t3, nullType(),
319 nullType(), nullType(), nullType(), nullType(),
320 nullType())
321 {}
322
323 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
324 typename TupleAccessTraits<T2>::ParameterType t2,
325 typename TupleAccessTraits<T3>::ParameterType t3,
326 typename TupleAccessTraits<T4>::ParameterType t4)
327 : FirstPair(t1, t2, t3, t4,
328 nullType(), nullType(), nullType(), nullType(),
329 nullType())
330 {}
331
332 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
333 typename TupleAccessTraits<T2>::ParameterType t2,
334 typename TupleAccessTraits<T3>::ParameterType t3,
335 typename TupleAccessTraits<T4>::ParameterType t4,
336 typename TupleAccessTraits<T5>::ParameterType t5)
337 : FirstPair(t1, t2, t3, t4,
338 t5, nullType(), nullType(), nullType(),
339 nullType())
340 {}
341
342 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
343 typename TupleAccessTraits<T2>::ParameterType t2,
344 typename TupleAccessTraits<T3>::ParameterType t3,
345 typename TupleAccessTraits<T4>::ParameterType t4,
346 typename TupleAccessTraits<T5>::ParameterType t5,
347 typename TupleAccessTraits<T6>::ParameterType t6)
348 : FirstPair(t1, t2, t3, t4,
349 t5, t6, nullType(), nullType(),
350 nullType())
351 {}
352
353 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
354 typename TupleAccessTraits<T2>::ParameterType t2,
355 typename TupleAccessTraits<T3>::ParameterType t3,
356 typename TupleAccessTraits<T4>::ParameterType t4,
357 typename TupleAccessTraits<T5>::ParameterType t5,
358 typename TupleAccessTraits<T6>::ParameterType t6,
359 typename TupleAccessTraits<T7>::ParameterType t7)
360 : FirstPair(t1, t2, t3, t4,
361 t5, t6, t7, nullType(),
362 nullType())
363 {}
364
365 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
366 typename TupleAccessTraits<T2>::ParameterType t2,
367 typename TupleAccessTraits<T3>::ParameterType t3,
368 typename TupleAccessTraits<T4>::ParameterType t4,
369 typename TupleAccessTraits<T5>::ParameterType t5,
370 typename TupleAccessTraits<T6>::ParameterType t6,
371 typename TupleAccessTraits<T7>::ParameterType t7,
372 typename TupleAccessTraits<T8>::ParameterType t8)
373 : FirstPair(t1, t2, t3, t4,
374 t5, t6, t7, t8,
375 nullType())
376 {}
377
378 tuple(typename TupleAccessTraits<T1>::ParameterType t1,
379 typename TupleAccessTraits<T2>::ParameterType t2,
380 typename TupleAccessTraits<T3>::ParameterType t3,
381 typename TupleAccessTraits<T4>::ParameterType t4,
382 typename TupleAccessTraits<T5>::ParameterType t5,
383 typename TupleAccessTraits<T6>::ParameterType t6,
384 typename TupleAccessTraits<T7>::ParameterType t7,
385 typename TupleAccessTraits<T8>::ParameterType t8,
386 typename TupleAccessTraits<T9>::ParameterType t9)
387 : FirstPair(t1, t2, t3, t4, t5, t6, t7, t8, t9)
388 {}
389
390 template<class U1, class U2>
391 tuple& operator=(const Pair<U1,U2>& other)
392 {
394 return *this;
395 }
396 };
397
398#endif
399
400#ifdef HAVE_TUPLE
401 using std::tuple_element;
402#elif defined HAVE_TR1_TUPLE
403 using std::tr1::tuple_element;
404#else
408 template<int N, class Tuple>
410 {
416 };
417
418 template<int N, typename T1, typename T2>
419 struct tuple_element<N,Pair<T1,T2> >
420 {
424 typedef typename tuple_element<N-1,T2>::Type type;
425 typedef typename tuple_element<N-1,T2>::Type Type;
426 };
427
431 template<typename T1, typename T2>
432 struct tuple_element<0, Pair<T1,T2> >
433 {
437 typedef T1 type;
438 typedef T1 Type;
439 };
440
441#endif
442
443#if defined HAVE_TUPLE || defined HAVE_TR1_TUPLE
444#ifdef HAVE_TUPLE
445 using std::get;
446#elif defined HAVE_TR1_TUPLE
447 using std::tr1::get;
448#endif
449
450#else
456 template<int N>
457 struct Element
458 {
464 template<typename T1, typename T2>
465 static typename TupleAccessTraits<
466 typename tuple_element<N,Pair<T1,T2> >::type
467 >::NonConstType
469 {
471 }
472
478 template<typename T1, typename T2>
479 static typename TupleAccessTraits<
480 typename tuple_element<N,Pair<T1,T2> >::type
481 >::ConstType
483 {
485 }
486 };
487
491 template<>
492 struct Element<0>
493 {
499 template<typename T1, typename T2>
500 static typename TupleAccessTraits<T1>::NonConstType get(Pair<T1,T2>& tuple)
501 {
502 return tuple.first();
503 }
504
510 template<typename T1, typename T2>
511 static typename TupleAccessTraits<T1>::ConstType get(const Pair<T1,T2>& tuple)
512 {
513 return tuple.first();
514 }
515 };
516
517 template<int i, typename T1, typename T2, typename T3, typename T4,
518 typename T5, typename T6, typename T7, typename T8, typename T9>
519 typename TupleAccessTraits<typename tuple_element<i, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> >::type>
520 ::NonConstType
521 get(tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9>& t)
522 {
523 return Element<i>::get(t);
524 }
525
526 template<int i, typename T1, typename T2, typename T3, typename T4,
527 typename T5, typename T6, typename T7, typename T8, typename T9>
528 typename TupleAccessTraits<typename tuple_element<i, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> >::type>
529 ::ConstType
530 get(const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9>& t)
531 {
532 return Element<i>::get(t);
533 }
534
535#endif
536
537#ifdef HAVE_TUPLE
538 using std::tuple_size;
539#elif defined HAVE_TR1_TUPLE
540 using std::tr1::tuple_size;
541#else
546 template<class T>
548 {
549 enum {
550 // @brief The number of Elements in the tuple.
552 };
553
554
555 };
556
557 template<typename T1, typename T2>
558 struct tuple_size<Pair<T1,T2> >
559 {
560 enum { value=1+tuple_size<T2>::value};
561 };
562
563
564 template<typename T1>
565 struct tuple_size<Pair<T1,Nil> >
566 {
567 enum { value=1};
568 };
569
570 template<>
571 struct tuple_size<Pair<Nil,Nil> >
572 {
573 enum { value=0};
574 };
575#endif
576
577
578#ifdef HAVE_TUPLE
579 using std::tie;
580 using std::make_tuple;
581#elif defined HAVE_TR1_TUPLE
582 using std::tr1::tie;
583 using std::tr1::make_tuple;
584#endif
585
586
587 template<int i>
588 struct tuple_writer
589 {
590 template<class T>
591 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
592 {
593 return tuple_writer<i-1>::put(os,t,delim)<<delim<<Dune::get<i-1>(t);
594 }
595
596 template< class T >
597 static std::istream &get ( std::istream &is, T &t, const char *delim = "," )
598 {
599 tuple_writer< i-1 >::get( is, t, delim );
600 for( const char *it = delim; is && (*it != 0); ++it )
601 {
602 char c = 0;
603 is >> c;
604 if( c != *it )
605 is.setstate( std::ios::failbit );
606 }
607 return is >> Dune::get< i-1 >( t );
608 }
609 };
610
611 template<>
612 struct tuple_writer<1>
613 {
614 template<class T>
615 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
616 {
618 return os<<Dune::get<0>(t);
619 }
620
621 template< class T >
622 static std::istream &get ( std::istream &is, T &t, const char *delim = ", " )
623 {
624 return is >> Dune::get< 0 >( t );
625 }
626 };
627
628 template<>
629 struct tuple_writer<0>
630 {
631 template<class T>
632 static std::ostream& put(std::ostream& os, const T& t, const char* delim=", ")
633 {
634 return os;
635 }
636
637 template< class T >
638 static std::istream &get ( std::istream &is, T &t, const char *delim = ", " )
639 {
640 return is;
641 }
642 };
643
644#if defined HAVE_TUPLE || defined HAVE_TR1_TUPLE
648 template<typename T1>
649 inline std::ostream& operator<<( std::ostream& os, const tuple<T1> & t)
650 {
651 typedef tuple<T1> TupleT;
652 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
653 }
654
655 template<typename T1, typename T2>
656 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2> & t)
657 {
658 typedef tuple<T1,T2> TupleT;
659 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
660 }
661
662 template<typename T1, typename T2, typename T3>
663 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3> & t)
664 {
665 typedef tuple<T1,T2,T3> TupleT;
666 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
667 }
668
669 template<typename T1, typename T2, typename T3, typename T4>
670 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4> & t)
671 {
672 typedef tuple<T1,T2,T3,T4> TupleT;
673 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
674 }
675
676 template<typename T1, typename T2, typename T3, typename T4, typename T5>
677 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5> & t)
678 {
679 typedef tuple<T1,T2,T3,T4,T5> TupleT;
680 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
681 }
682
683 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
684 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6> & t)
685 {
686 typedef tuple<T1,T2,T3,T4,T5,T6> TupleT;
687 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
688 }
689
690 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
691 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7> & t)
692 {
693 typedef tuple<T1,T2,T3,T4,T5,T6,T7> TupleT;
694 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
695 }
696
697 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
698 typename T8>
699 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8> & t)
700 {
701 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8> TupleT;
702 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
703 }
704
705 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
706 typename T8, typename T9>
707 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> & t)
708 {
709 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> TupleT;
710 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
711 }
712
713 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
714 typename T8, typename T9, typename T10>
715 inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> & t)
716 {
717 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> TupleT;
718 return tuple_writer<tuple_size<TupleT>::value>::put(os, t);
719 }
720
724 template<typename T1>
725 inline std::istream& operator>>( std::istream& is, tuple<T1> & t)
726 {
727 typedef tuple<T1> TupleT;
728 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
729 }
730
731 template<typename T1, typename T2>
732 inline std::istream& operator>>( std::istream& is, tuple<T1,T2> & t)
733 {
734 typedef tuple<T1,T2> TupleT;
735 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
736 }
737
738 template<typename T1, typename T2, typename T3>
739 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3> & t)
740 {
741 typedef tuple<T1,T2,T3> TupleT;
742 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
743 }
744
745 template<typename T1, typename T2, typename T3, typename T4>
746 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4> & t)
747 {
748 typedef tuple<T1,T2,T3,T4> TupleT;
749 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
750 }
751
752 template<typename T1, typename T2, typename T3, typename T4, typename T5>
753 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5> & t)
754 {
755 typedef tuple<T1,T2,T3,T4,T5> TupleT;
756 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
757 }
758
759 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
760 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6> & t)
761 {
762 typedef tuple<T1,T2,T3,T4,T5,T6> TupleT;
763 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
764 }
765
766 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
767 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7> & t)
768 {
769 typedef tuple<T1,T2,T3,T4,T5,T6,T7> TupleT;
770 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
771 }
772
773 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
774 typename T8>
775 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8> & t)
776 {
777 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8> TupleT;
778 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
779 }
780
781 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
782 typename T8, typename T9>
783 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> & t)
784 {
785 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> TupleT;
786 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
787 }
788
789 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7,
790 typename T8, typename T9, typename T10>
791 inline std::istream& operator>>( std::istream& is, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> & t)
792 {
793 typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> TupleT;
794 return tuple_writer<tuple_size<TupleT>::value>::get(is, t);
795 }
796#else
802 template<typename T1, typename T2, typename U1, typename U2>
803 inline bool operator==(const Pair<T1,T2>& tuple1, const Pair<U1,U2>& tuple2)
804 {
805 return (tuple1.first()==tuple2.first() && tuple1.second()==tuple2.second());
806 }
807
813 template<typename T1, typename T2, typename U1, typename U2>
814 inline bool operator!=(const Pair<T1,T2>& tuple1, const Pair<U1,U2>& tuple2)
815 {
816 return (tuple1.first()!=tuple2.first() || tuple1.second()!=tuple2.second());
817 }
818
824 template<typename T1, typename T2, typename U1, typename U2>
825 inline bool operator<(const Pair<T1,T2>& tuple1, const Pair<U1,U2>& tuple2)
826 {
827 return tuple1.first() < tuple2.first()
828 || (tuple1.first() == tuple2.first() && tuple1.second() < tuple2.second());
829 }
830
836 template<typename T1,typename U1>
837 inline bool operator==(const Pair<T1,Nil>& tuple1, const Pair<U1,Nil>& tuple2)
838 {
839 return (tuple1.first()==tuple2.first());
840 }
841
847 template<typename T1, typename U1>
848 inline bool operator!=(const Pair<T1,Nil>& tuple1, const Pair<U1,Nil>& tuple2)
849 {
851 "T1 and U1 have to be interoperable, i.e., either "
852 "conversion from one to the other must exist." );
853 return (tuple1.first()!=tuple2.first());
854 }
855
861 template<typename T1, typename U1>
862 inline bool operator<(const Pair<T1,Nil>& tuple1, const Pair<U1,Nil>& tuple2)
863 {
864 return (tuple1.first()<tuple2.first());
865 }
866
874 template<typename T1,typename U1, typename U2>
875 inline bool operator==(const Pair<T1,Nil>& tuple1, const Pair<U1,U2>& tuple2)
876 {
877 return false;
878 }
879
886 template<typename T1, typename U1, typename U2>
887 inline bool operator!=(const Pair<T1,Nil>& tuple1, const Pair<U1,U2>& tuple2)
888 {
889 return true;
890 }
891
892
899 template<typename T1, typename T2, typename U1>
900 inline bool operator==(const Pair<T1,T2>& tuple1, const Pair<U1,Nil>& tuple2)
901 {
902 return false;
903 }
904
911 template<typename T1, typename T2, typename U1>
912 inline bool operator!=(const Pair<T1,T2>& tuple1, const Pair<U1,Nil>& tuple2)
913 {
914 return true;
915 }
916
922 template<typename T1, typename T2>
923 inline Pair<T1,T2> makePair(const T1& first, const T2& second)
924 {
925 return Pair<T1,T2>(first, second);
926 }
927
931 template<typename T1, typename T2>
932 inline std::ostream& operator<<(std::ostream& os, const Pair<T1,T2>& pair)
933 {
934 os<<pair.first()<<" "<<pair.second();
935 return os;
936 }
937
938 template<typename T1>
939 inline std::ostream& operator<<(std::ostream& os, const Pair<T1,Nil>& pair)
940 {
941 os<<pair.first();
942 return os;
943 }
944
948 template<typename T1, typename T2>
949 inline std::istream& operator>>(std::istream& is, Pair<T1,T2>& pair)
950 {
951 return is >> pair.first() >> pair.second();
952 }
953
954 template<typename T1>
955 inline std::istream& operator>>(std::istream& is, Pair<T1,Nil>& pair)
956 {
957 return is >> pair.first();
958 }
959
960 template<class T1>
961 inline tuple<T1&> tie(T1& t1) {
962 return tuple<T1&> (t1);
963 }
964
965 template<class T1, class T2>
966 inline tuple<T1&, T2&> tie(T1& t1, T2& t2) {
967 return tuple<T1&, T2&> (t1, t2);
968 }
969
970 template<class T1, class T2, class T3>
971 inline tuple<T1&, T2&, T3&> tie(T1& t1, T2& t2, T3& t3) {
972 return tuple<T1&, T2&, T3&> (t1, t2, t3);
973 }
974
975 template<class T1, class T2, class T3, class T4>
976 inline tuple<T1&, T2&, T3&, T4&> tie(T1& t1, T2& t2, T3& t3, T4& t4) {
977 return tuple<T1&, T2&, T3&, T4&> (t1, t2, t3, t4);
978 }
979
980 template<class T1, class T2, class T3, class T4, class T5>
981 inline tuple<T1&, T2&, T3&, T4&, T5&>
982 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) {
983 return tuple<T1&, T2&, T3&, T4&, T5&> (t1, t2, t3, t4, t5);
984 }
985
986 template<class T1, class T2, class T3, class T4, class T5, class T6>
987 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&>
988 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6) {
989 return tuple<T1&, T2&, T3&, T4&, T5&, T6&> (t1, t2, t3, t4, t5, t6);
990 }
991
992 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
993 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&>
994 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7) {
995 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&> (t1, t2, t3, t4, t5, t6, t7);
996 }
997
998 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
999 class T8>
1000 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&>
1001 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8) {
1002 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&>
1003 (t1, t2, t3, t4, t5, t6, t7, t8);
1004 }
1005
1006 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
1007 class T8, class T9>
1008 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&>
1009 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, T9& t9) {
1010 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&>
1011 (t1, t2, t3, t4, t5, t6, t7, t8, t9);
1012 }
1013
1014 template<class T1>
1015 inline tuple<T1> make_tuple(const T1& t1) {
1016 return tuple<T1> (t1);
1017 }
1018
1019 template<class T1, class T2>
1020 inline tuple<T1, T2> make_tuple(const T1& t1, const T2& t2) {
1021 return tuple<T1, T2> (t1, t2);
1022 }
1023
1024 template<class T1, class T2, class T3>
1025 inline tuple<T1, T2, T3> make_tuple(const T1& t1, const T2& t2, const T3& t3) {
1026 return tuple<T1, T2, T3> (t1, t2, t3);
1027 }
1028
1029 template<class T1, class T2, class T3, class T4>
1030 inline tuple<T1, T2, T3, T4> make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4) {
1031 return tuple<T1, T2, T3, T4> (t1, t2, t3, t4);
1032 }
1033
1034 template<class T1, class T2, class T3, class T4, class T5>
1035 inline tuple<T1, T2, T3, T4, T5>
1036 make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) {
1037 return tuple<T1, T2, T3, T4, T5> (t1, t2, t3, t4, t5);
1038 }
1039
1040 template<class T1, class T2, class T3, class T4, class T5, class T6>
1041 inline tuple<T1, T2, T3, T4, T5, T6>
1042 make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6) {
1043 return tuple<T1, T2, T3, T4, T5, T6> (t1, t2, t3, t4, t5, t6);
1044 }
1045
1046 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
1047 inline tuple<T1, T2, T3, T4, T5, T6, T7>
1048 make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6,
1049 const T7& t7) {
1050 return tuple<T1, T2, T3, T4, T5, T6, T7> (t1, t2, t3, t4, t5, t6, t7);
1051 }
1052
1053 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
1054 class T8>
1055 inline tuple<T1, T2, T3, T4, T5, T6, T7, T8>
1056 make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6,
1057 const T7& t7, const T8& t8) {
1058 return tuple<T1, T2, T3, T4, T5, T6, T7, T8>
1059 (t1, t2, t3, t4, t5, t6, t7, t8);
1060 }
1061
1062 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
1063 class T8, class T9>
1064 inline tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>
1065 make_tuple(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6,
1066 const T7& t7, const T8& t8, const T9& t9) {
1067 return tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>
1068 (t1, t2, t3, t4, t5, t6, t7, t8, t9);
1069 }
1070
1071 template<typename T1, typename TT>
1072 template<typename T2, typename T3, typename T4, typename T5,
1073 typename T6, typename T7, typename T8, typename T9>
1074 inline Pair<T1,TT>::Pair(typename TupleAccessTraits<T1>::ParameterType first,
1075 T2& t2, T3& t3, T4& t4, T5& t5,
1076 T6& t6, T7& t7, T8& t8, T9& t9)
1077 : first_(first), second_(t2,t3,t4,t5,t6,t7,t8,t9, nullType())
1078 {}
1079
1080 template <typename T1, typename TT>
1081 inline Pair<T1, TT>::Pair(typename TupleAccessTraits<T1>::ParameterType first, TT& second)
1082 : first_(first), second_(second)
1083 {}
1084
1085 template<typename T1, typename T2>
1086 inline Pair<T1,T2>::Pair()
1087 : first_(), second_()
1088 {}
1089
1090 template<typename T1, typename T2>
1091 template<typename U1, typename U2>
1092 inline Pair<T1,T2>::Pair(const Pair<U1,U2>& other)
1093 : first_(other.first_), second_(other.second_)
1094 {}
1095
1096 template<typename T1, typename T2>
1097 template<typename U1, typename U2>
1098 inline Pair<T1,T2>& Pair<T1,T2>::operator=(const Pair<U1,U2>& other)
1099 {
1100 first_=other.first_;
1101 second_=other.second_;
1102 return *this;
1103 }
1104
1105 template<typename T1, typename T2>
1106 inline Pair<T1,T2>& Pair<T1,T2>::operator=(const Pair& other)
1107 {
1108 first_=other.first_;
1109 second_=other.second_;
1110 return *this;
1111 }
1112
1113 template<typename T1, typename T2>
1114 inline typename TupleAccessTraits<T1>::NonConstType
1116 {
1117 return first_;
1118 }
1119
1120 template<typename T1, typename T2>
1121 inline typename TupleAccessTraits<T1>::ConstType
1123 {
1124 return first_;
1125 }
1126
1127
1128 template<typename T1, typename T2>
1129 inline typename TupleAccessTraits<T2>::NonConstType
1131 {
1132 return second_;
1133 }
1134
1135 template<typename T1, typename T2>
1136 inline typename TupleAccessTraits<T2>::ConstType
1138 {
1139 return second_;
1140 }
1141
1142 template<typename T1>
1143 inline Pair<T1,Nil>::Pair(typename TupleAccessTraits<T1>::ParameterType first,
1144 const Nil&, const Nil&, const Nil&, const Nil&,
1145 const Nil&, const Nil&, const Nil&, const Nil&)
1146 : first_(first)
1147 {}
1148
1149 template <typename T1>
1150 inline Pair<T1, Nil>::Pair(typename TupleAccessTraits<T1>::ParameterType first,
1151 const Nil&)
1152 : first_(first)
1153 {}
1154
1155 template<typename T1>
1156 inline Pair<T1,Nil>::Pair()
1157 : first_()
1158 {}
1159
1160 template<typename T1>
1161 template<typename T2>
1163 : first_(other.first_)
1164 {}
1165
1166 template<typename T1>
1167 template<typename T2>
1169 {
1170 first_ = other.first_;
1171 return *this;
1172 }
1173
1174
1175 template<typename T1>
1177 {
1178 first_ = other.first_;
1179 return *this;
1180 }
1181
1182 template<typename T1>
1183 inline typename TupleAccessTraits<T1>::NonConstType
1185 {
1186 return first_;
1187 }
1188
1189 template<typename T1>
1190 inline typename TupleAccessTraits<T1>::ConstType
1192 {
1193 return first_;
1194 }
1195
1197#endif
1198}
1199#endif
A Tuple of objects.
Definition: tuples.hh:294
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
static TupleAccessTraits< T1 >::ConstType get(const Pair< T1, T2 > &tuple)
Get the first element of the tuple.
Definition: tuples.hh:511
static TupleAccessTraits< typenametuple_element< N, Pair< T1, T2 > >::type >::ConstType get(const Pair< T1, T2 > &tuple)
Get the N-th element of the tuple.
Definition: tuples.hh:482
TupleAccessTraits< Type2 >::NonConstType second()
Get the second value.
Definition: tuples.hh:1130
Nil Type2
The type of the (non-existent) second field is Nil. This typedef is useful in template metaprogrammin...
Definition: tuples.hh:200
Type1 first_
The value of the first field.
Definition: tuples.hh:177
Type2 second_
The value of the second field.
Definition: tuples.hh:179
tuple_element< N, typenameTuple::FirstPair >::type type
The type of the N-th element of the tuple.
Definition: tuples.hh:414
Pair< T1, T2 > makePair(const T1 &first, const T2 &second)
Create a tuple and initialize it.
Definition: tuples.hh:923
tuple_element< N-1, T2 >::Type type
The type of the N-th element of the tuple.
Definition: tuples.hh:424
Pair & operator=(const Pair< T2, Nil > &other)
Assignment operator for type conversion.
T1 type
The type of the first element of the tuple.
Definition: tuples.hh:437
static TupleAccessTraits< typenametuple_element< N, Pair< T1, T2 > >::type >::NonConstType get(Pair< T1, T2 > &tuple)
Get the N-th element of the tuple.
Definition: tuples.hh:468
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
T1 Type1
The type of the first field.
Definition: tuples.hh:92
TT Type2
The type of the second field.
Definition: tuples.hh:97
std::istream & operator>>(std::istream &is, Pair< T1, T2 > &pair)
Read a pair or tuple.
Definition: tuples.hh:949
TupleAccessTraits< Type1 >::NonConstType first()
Get the first value.
Definition: tuples.hh:1115
Pair & operator=(const Pair< U1, U2 > &other)
Assignment operator for implicit type conversion.
Type1 first_
The value of the first field.
Definition: tuples.hh:250
TupleToPairs< T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Type FirstPair
Type of the first Pair defining the Tuple.
Definition: tuples.hh:297
TupleAccessTraits< Type1 >::NonConstType first()
Get the first value.
Definition: tuples.hh:1184
T1 Type1
The type of the first field.
Definition: tuples.hh:193
static TupleAccessTraits< T1 >::NonConstType get(Pair< T1, T2 > &tuple)
Get the first element of the tuple.
Definition: tuples.hh:500
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:253
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the C++0x static_assert feature.
T UnqualifiedType
The unqualified type.
Definition: typetraits.hh:93
const T ConstType
The const type.
Definition: typetraits.hh:95
Get the N-th element of a tuple.
Definition: tuples.hh:458
Checks wether two types are interoperable.
Definition: typetraits.hh:308
An empty class.
Definition: tuples.hh:71
A tuple consisting of one object. Specialization of Pair that really is a single value.
Definition: tuples.hh:189
A tuple consisting of two objects.
Definition: tuples.hh:88
Converts the Tuple to a list of pairs.
Definition: tuples.hh:260
Get the type of the N-th element of the tuple.
Definition: tuples.hh:410
Template meta_programm to query the size of a tuple.
Definition: tuples.hh:548
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 12, 23:30, 2024)