dune-common 3.0-git
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>
35 {
36 typedef typename std::add_const<T>::type& ConstType;
37 typedef T& NonConstType;
38 typedef const typename std::remove_const<T>::type& ParameterType;
39 };
40
41 template<class T>
43 {
44 typedef typename std::add_const<T>::type* ConstType;
45 typedef T* NonConstType;
46 typedef T* ParameterType;
47 };
48
49 template<class 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>
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... Ts>
127 inline std::ostream& operator<<(std::ostream& os, const tuple<Ts...>& t)
128 {
129 return tuple_writer<sizeof...(Ts)>::put(os, t);
130 }
131
135 template<typename... Ts>
136 inline std::istream& operator>>(std::istream& is, tuple<Ts...>& t)
137 {
138 return tuple_writer<sizeof...(Ts)>::get(is, t);
139 }
140
142}
143#endif
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 intentionally unused function parameters with.
Definition unused.hh:18
static std::ostream & put(std::ostream &os, const T &t, const char *delim=", ")
Definition tuples.hh:70
std::add_const< T >::type & ConstType
Definition tuples.hh:36
static std::ostream & put(std::ostream &os, const T &t, const char *delim=", ")
Definition tuples.hh:111
T * ParameterType
Definition tuples.hh:46
std::ostream & operator<<(std::ostream &s, const std::array< T, N > &e)
Output operator for array.
Definition array.hh:28
static std::istream & get(std::istream &is, T &t, const char *delim=",")
Definition tuples.hh:76
T & ConstType
Definition tuples.hh:52
T * NonConstType
Definition tuples.hh:45
std::istream & operator>>(std::istream &is, tuple< Ts... > &t)
Read a tuple.
Definition tuples.hh:136
static std::istream & get(std::istream &is, T &t, const char *delim=", ")
Definition tuples.hh:117
T & NonConstType
Definition tuples.hh:53
T & NonConstType
Definition tuples.hh:37
static std::ostream & put(std::ostream &os, const T &t, const char *delim=", ")
Definition tuples.hh:94
static std::istream & get(std::istream &is, T &t, const char *delim=", ")
Definition tuples.hh:101
T & ParameterType
Definition tuples.hh:54
const std::remove_const< T >::type & ParameterType
Definition tuples.hh:38
std::add_const< T >::type * ConstType
Definition tuples.hh:44
Dune namespace.
Definition alignment.hh:11
void put(const RAPropertyMapHelper< Reference, PropertyMap > &pmap, const Key &key, const Value &value)
Definition propertymap.hh:90
Reference get(const RAPropertyMapHelper< Reference, PropertyMap > &pmap, const Key &key)
Definition propertymap.hh:82
Definition tuples.hh:35
Definition tuples.hh:68