Dune Core Modules (2.9.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 (C) 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 
23 namespace Dune
24 {
25 
26 
27 
33 template<class... T>
34 class 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 
45 public:
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 
89 template<class... T>
90 constexpr 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
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:30
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:141
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 3, 22:32, 2024)