diff --git a/common/tuples.hh b/common/tuples.hh index ebba0782b34f6389e031d9f34b6966ca52880e21..fe012e679f1ae3c0c7d37fe87e23a452d9b62004 100644 --- a/common/tuples.hh +++ b/common/tuples.hh @@ -10,8 +10,7 @@ #ifdef HAVE_TUPLE #include <tuple> -#endif -#ifdef HAVE_TR1_TUPLE +#elif defined HAVE_TR1_TUPLE #include <tr1/tuple> #endif @@ -438,8 +437,14 @@ namespace Dune { #endif #define ElementType tuple_element -#ifdef HAVE_TR1_TUPLE +#if defined HAVE_TUPLE || defined HAVE_TR1_TUPLE +#ifdef HAVE_TUPLE + #define TUPLE_NS std + using std::get; +#elif defined HAVE_TR1_TUPLE + #define TUPLE_NS std::tr1 using std::tr1::get; +#endif // for backwards compatibility template<int i> @@ -447,33 +452,17 @@ namespace Dune { template<typename T1> static typename TupleAccessTraits<typename tuple_element<i,T1>::type>::NonConstType get(T1& t) { - return std::tr1::get<i>(t); + return TUPLE_NS::get<i>(t); } template<typename T1> static typename TupleAccessTraits<typename tuple_element<i,T1>::type>::ConstType get(const T1& t) { - return std::tr1::get<i>(t); + return TUPLE_NS::get<i>(t); } }; -#elif defined HAVE_TUPLE - using std::get; - - // for backwards compatibility - template<int i> - struct Element { - template<typename T1> - static typename TupleAccessTraits<typename tuple_element<i,T1>::type>::NonConstType get(T1& t) - { - return std::get<i>(t); - } + #undef TUPLE_NS - template<typename T1> - static typename TupleAccessTraits<typename tuple_element<i,T1>::type>::ConstType get(const T1& t) - { - return std::get<i>(t); - } - }; #else /** * @brief Get the N-th element of a tuple. @@ -559,10 +548,10 @@ namespace Dune { #endif -#ifdef HAVE_TR1_TUPLE - using std::tr1::tuple_size; -#elif defined HAVE_TUPLE +#ifdef HAVE_TUPLE using std::tuple_size; +#elif defined HAVE_TR1_TUPLE + using std::tr1::tuple_size; #else /** * @brief Template meta_programm to query the size of a tuple @@ -601,13 +590,12 @@ namespace Dune { #define Size tuple_size -#ifdef HAVE_TR1_TUPLE - using std::tr1::tie; - using std::tr1::make_tuple; -#endif #ifdef HAVE_TUPLE using std::tie; using std::make_tuple; +#elif defined HAVE_TR1_TUPLE + using std::tr1::tie; + using std::tr1::make_tuple; #endif #if defined HAVE_TUPLE || defined HAVE_TR1_TUPLE @@ -634,14 +622,78 @@ namespace Dune { /** * \brief Print a tuple. */ + template<typename T1> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1> & t) + { + typedef tuple<T1> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2> & t) + { + typedef tuple<T1,T2> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3> & t) + { + typedef tuple<T1,T2,T3> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3, typename T4> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4> & t) + { + typedef tuple<T1,T2,T3,T4> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3, typename T4, typename T5> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5> & t) + { + typedef tuple<T1,T2,T3,T4,T5> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6> & t) + { + typedef tuple<T1,T2,T3,T4,T5,T6> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7> & t) + { + typedef tuple<T1,T2,T3,T4,T5,T6,T7> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + + template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, + typename T8> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8> & t) + { + typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } + template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> - inline std::ostream& operator<<( std::ostream& os, tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> t) + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> & t) { typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9> Tuple; return tuple_writer<tuple_size<Tuple>::value>::put(os, t); } + template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, + typename T8, typename T9, typename T10> + inline std::ostream& operator<<( std::ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> & t) + { + typedef tuple<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> Tuple; + return tuple_writer<tuple_size<Tuple>::value>::put(os, t); + } #else /**