Dune Core Modules (2.5.2)

streamoperators.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_STREAMOPERATORS_HH
5#define DUNE_STREAMOPERATORS_HH
6
11#include <array>
12#include <tuple>
13
14#include <dune/common/hybridutilities.hh>
15#include <dune/common/std/utility.hh>
16
17namespace Dune
18{
25 template<typename Stream, typename... Ts>
26 inline Stream& operator<<(Stream& stream, const std::tuple<Ts...>& t)
27 {
28 stream<<"[";
29 if(sizeof...(Ts)>0)
30 {
31 Hybrid::forEach(Std::make_index_sequence<sizeof...(Ts)-1>{},
32 [&](auto i){stream<<std::get<i>(t)<<",";});
33 stream<<std::get<sizeof...(Ts)-1>(t);
34 }
35 stream<<"]";
36 return stream;
37 }
38
40 template<typename Stream, typename... Ts>
41 inline Stream& operator>>(Stream& stream, std::tuple<Ts...>& t)
42 {
43 Hybrid::forEach(Std::make_index_sequence<sizeof...(Ts)>{},
44 [&](auto i){stream>>std::get<i>(t);});
45 return stream;
46 }
47
49 template<typename Stream, typename T, std::size_t N>
50 inline Stream& operator<<(Stream& stream, const std::array<T,N>& a)
51 {
52 stream<<"[";
53 if(N>0)
54 {
55 for(std::size_t i=0; i<N-1; ++i)
56 stream<<a[i]<<",";
57 stream<<a[N-1];
58 }
59 stream<<"]";
60 return stream;
61 }
62
65} // end namespace Dune
66
67#endif
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:41
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:314
Dune namespace.
Definition: alignment.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)