Dune Core Modules (2.5.0)

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_COMMON_TUPLEVECTOR_HH
4#define DUNE_COMMON_TUPLEVECTOR_HH
5
6#include <tuple>
7#include <utility>
8
9#include <dune/common/indices.hh>
10
11
12
19namespace Dune
20{
21
22
23
29template<class... T>
30class TupleVector : public std::tuple<T...>
31{
32 using Base = std::tuple<T...>;
33
34public:
35
38 template<class... TT>
39 constexpr TupleVector(TT&&... tt) :
40 Base(std::forward<TT>(tt)...)
41 {}
42
45 constexpr TupleVector()
46 {}
47
50 template<std::size_t i>
51 constexpr decltype(auto) operator[](const Dune::index_constant<i>&) const
52 {
53 return std::get<i>(*this);
54 }
55
58 template<std::size_t i>
59 decltype(auto) operator[](const Dune::index_constant<i>&)
60 {
61 return std::get<i>(*this);
62 }
63
65 static constexpr std::size_t size()
66 {
67 return std::tuple_size<Base>::value;
68 }
69};
70
71
72
73template<class... T>
74constexpr auto makeTupleVector(T&&... t)
75{
76 // The std::decay_t<T> is is a slight simplification,
77 // because std::reference_wrapper needs special care.
78 return TupleVector<std::decay_t<T>...>(std::forward<T>(t)...);
79}
80
81
82
83} // namespace Dune
84
85#endif // DUNE_COMMON_TUPLEVECTOR_HH
A class augmenting std::tuple by element access via operator[].
Definition: tuplevector.hh:31
static constexpr std::size_t size()
Number of elements of the tuple.
Definition: tuplevector.hh:65
constexpr TupleVector(TT &&... tt)
Construct from a set of arguments.
Definition: tuplevector.hh:39
constexpr TupleVector()
Default constructor.
Definition: tuplevector.hh:45
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:26
Dune namespace.
Definition: alignment.hh:11
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)