Dune Core Modules (unstable)

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