dune-common  2.11
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 
18 
19 namespace Dune
20 {
26  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::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:301
std::istream & operator>>(std::istream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
I i
Definition: hybridmultiindex.hh:328
Dune namespace
Definition: alignedallocator.hh:12
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:261