dune-functions  2.5-dev
tuplevector.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 #ifndef DUNE_FUNCTIONS_COMMON_TUPLEVECTOR_HH
4 #define DUNE_FUNCTIONS_COMMON_TUPLEVECTOR_HH
5 
6 #include <tuple>
7 
8 #include <dune/common/indices.hh>
9 
10 namespace Dune
11 {
12 namespace Functions
13 {
14 
20  template<class... T>
21  class TupleVector : public std::tuple<T...>
22  {
23  using Base = std::tuple<T...>;
24 
25  public:
26 
28  template<class... TT>
29  constexpr TupleVector(TT&&... tt) :
30  Base(std::forward<TT>(tt)...)
31  {}
32 
34  constexpr TupleVector()
35  {}
36 
38  template<std::size_t i>
39  auto operator[](const Dune::index_constant<i>&) const
40  ->decltype(std::get<i>(*this))
41  {
42  return std::get<i>(*this);
43  }
44 
46  template<std::size_t i>
47  auto operator[](const Dune::index_constant<i>&)
48  ->decltype(std::get<i>(*this))
49  {
50  return std::get<i>(*this);
51  }
52 
54  static constexpr std::size_t size()
55  {
56  return std::tuple_size<Base>::value;
57  }
58 
59  };
60 
61 } // namespace Functions
62 
63 } // namespace Dune
64 
65 #endif
A class augmenting std::tuple by element access via operator[].
Definition: tuplevector.hh:21
Definition: polynomial.hh:7
STL namespace.
static constexpr std::size_t size()
Number of elements of the tuple.
Definition: tuplevector.hh:54
auto operator[](const Dune::index_constant< i > &) -> decltype(std::get< i >(*this))
Non-const access to the tuple elements.
Definition: tuplevector.hh:47
constexpr TupleVector()
Default constructor.
Definition: tuplevector.hh:34
constexpr TupleVector(TT &&... tt)
Construct from a set of arguments.
Definition: tuplevector.hh:29
auto operator[](const Dune::index_constant< i > &) const -> decltype(std::get< i >(*this))
Const access to the tuple elements.
Definition: tuplevector.hh:39