Dune Core Modules (2.8.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>
11#include <dune/common/std/type_traits.hh>
12
13
14
21namespace Dune
22{
23
24
25
31template<class... T>
32class TupleVector : public std::tuple<T...>
33{
34 using Base = std::tuple<T...>;
35
36 template<class... TT>
37 using TupleConstructorDetector = decltype(Base(std::declval<TT&&>()...));
38
39 template<class... TT>
40 using hasTupleConstructor = Dune::Std::is_detected<TupleConstructorDetector, TT...>;
41
42
43public:
44
51 template<class... TT,
52 std::enable_if_t<hasTupleConstructor<TT...>::value, int> = 0>
53 constexpr TupleVector(TT&&... tt) :
54 Base(std::forward<TT>(tt)...)
55 {}
56
59 constexpr TupleVector()
60 {}
61
64 template<std::size_t i>
65 constexpr decltype(auto) operator[](const Dune::index_constant<i>&) const
66 {
67 return std::get<i>(*this);
68 }
69
72 template<std::size_t i>
73 decltype(auto) operator[](const Dune::index_constant<i>&)
74 {
75 return std::get<i>(*this);
76 }
77
79 static constexpr std::size_t size()
80 {
81 return std::tuple_size<Base>::value;
82 }
83};
84
85
86
87template<class... T>
88constexpr auto makeTupleVector(T&&... t)
89{
90 // The std::decay_t<T> is is a slight simplification,
91 // because std::reference_wrapper needs special care.
92 return TupleVector<std::decay_t<T>...>(std::forward<T>(t)...);
93}
94
95
96
97} // namespace Dune
98
99#endif // DUNE_COMMON_TUPLEVECTOR_HH
A class augmenting std::tuple by element access via operator[].
Definition: tuplevector.hh:33
static constexpr std::size_t size()
Number of elements of the tuple.
Definition: tuplevector.hh:79
constexpr TupleVector(TT &&... tt)
Construct from a set of arguments.
Definition: tuplevector.hh:53
constexpr TupleVector()
Default constructor.
Definition: tuplevector.hh:59
Traits for type conversions and type information.
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:326
Dune namespace.
Definition: alignedallocator.hh:11
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)