Dune Core Modules (2.10.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// 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 std::enable_if_t<(i < sizeof...(T)), int> = 0>
68 constexpr decltype(auto) operator[](const Dune::index_constant<i>&) const
69 {
70 return std::get<i>(*this);
71 }
72
75 template<std::size_t i,
76 std::enable_if_t<(i < sizeof...(T)), int> = 0>
77 decltype(auto) operator[](const Dune::index_constant<i>&)
78 {
79 return std::get<i>(*this);
80 }
81
83 static constexpr std::size_t size()
84 {
85 return std::tuple_size<Base>::value;
86 }
87};
88
89
90
91template<class... T>
92constexpr auto makeTupleVector(T&&... t)
93{
94 // The std::decay_t<T> is is a slight simplification,
95 // because std::reference_wrapper needs special care.
96 return TupleVector<std::decay_t<T>...>(std::forward<T>(t)...);
97}
98
99
100
101} // namespace Dune
102
103namespace std
104{
109 template <size_t i, typename... Args>
110 struct tuple_element<i,Dune::TupleVector<Args...> >
111 {
112 using type = typename std::tuple_element<i, std::tuple<Args...> >::type;
113 };
114
119 template <typename... Args>
120 struct tuple_size<Dune::TupleVector<Args...> >
121 : std::integral_constant<std::size_t, sizeof...(Args)>
122 {};
123}
124
125#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:83
constexpr TupleVector(TT &&... tt)
Construct from a set of arguments.
Definition: tuplevector.hh:55
constexpr TupleVector()
Default constructor.
Definition: tuplevector.hh:61
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: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.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)