Dune Core Modules (unstable)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6#ifndef DUNE_STREAMOPERATORS_HH
7#define DUNE_STREAMOPERATORS_HH
8
13#include <array>
14#include <tuple>
15#include <utility>
16
17#include <dune/common/hybridutilities.hh>
18
19namespace Dune
20{
27 template<typename... Ts>
28 inline std::ostream& operator<<(std::ostream& stream, const std::tuple<Ts...>& t)
29 {
30 stream<<"[";
31 if(sizeof...(Ts)>0)
32 {
33 Hybrid::forEach(std::make_index_sequence<sizeof...(Ts)-1>{},
34 [&](auto i){stream<<std::get<i>(t)<<",";});
35 stream<<std::get<sizeof...(Ts)-1>(t);
36 }
37 stream<<"]";
38 return stream;
39 }
40
42 template<typename... Ts>
43 inline std::istream& operator>>(std::istream& stream, std::tuple<Ts...>& t)
44 {
45 Hybrid::forEach(std::make_index_sequence<sizeof...(Ts)>{},
46 [&](auto i){stream>>std::get<i>(t);});
47 return stream;
48 }
49
51 template<typename T, std::size_t N>
52 inline std::ostream& operator<<(std::ostream& stream, const std::array<T,N>& a)
53 {
54 stream<<"[";
55 if(N>0)
56 {
57 for(std::size_t i=0; i<N-1; ++i)
58 stream<<a[i]<<",";
59 stream<<a[N-1];
60 }
61 stream<<"]";
62 return stream;
63 }
64
67} // end namespace Dune
68
69#endif
std::istream & operator>>(std::istream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)