Loading...
Searching...
No Matches
tuplevector.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_TUPLEVECTOR_HH
#define DUNE_COMMON_TUPLEVECTOR_HH
#include <tuple>
#include <utility>
#include <dune/common/indices.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/std/type_traits.hh>
namespace Dune
{
template<class... T>
class TupleVector : public std::tuple<T...>
{
using Base = std::tuple<T...>;
public:
template<class... TT,
class = std::void_t<decltype(Base(std::declval<TT&&>()...))>>
constexpr TupleVector(TT&&... tt) :
Base(std::forward<TT>(tt)...)
{}
constexpr TupleVector()
{}
template<std::size_t i,
std::enable_if_t<(i < sizeof...(T)), int> = 0>
constexpr decltype(auto) operator[](const Dune::index_constant<i>&) const
{
return std::get<i>(*this);
}
template<std::size_t i,
std::enable_if_t<(i < sizeof...(T)), int> = 0>
constexpr decltype(auto) operator[](const Dune::index_constant<i>&)
{
return std::get<i>(*this);
}
static constexpr std::size_t size()
{
return std::tuple_size<Base>::value;
}
};
template<class... T>
TupleVector(T...) -> TupleVector<T...>;
template<class T1, class T2>
TupleVector(std::pair<T1, T2>) -> TupleVector<T1, T2>;
template<class... T>
TupleVector(std::tuple<T...>) -> TupleVector<T...>;
template <class Alloc, class... T>
TupleVector(std::allocator_arg_t, Alloc, T...) -> TupleVector<T...>;
template<class Alloc, class T1, class T2>
TupleVector(std::allocator_arg_t, Alloc, std::pair<T1, T2>) -> TupleVector<T1, T2>;
template<class Alloc, class... T>
TupleVector(std::allocator_arg_t, Alloc, std::tuple<T...>) -> TupleVector<T...>;
template<class... T>
constexpr auto makeTupleVector(T&&... t)
{
// The std::decay_t<T> is is a slight simplification,
// because std::reference_wrapper needs special care.
return TupleVector<std::decay_t<T>...>(std::forward<T>(t)...);
}
} // namespace Dune
namespace std
{
template <size_t i, typename... Args>
struct tuple_element<i,Dune::TupleVector<Args...> >
{
using type = typename std::tuple_element<i, std::tuple<Args...> >::type;
};
template <typename... Args>
struct tuple_size<Dune::TupleVector<Args...> >
: std::integral_constant<std::size_t, sizeof...(Args)>
{};
}
#endif // DUNE_COMMON_TUPLEVECTOR_HH
typetraits.hh
Traits for type conversions and type information.
type_traits.hh
indices.hh
Dune::index_constant
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition indices.hh:29
std
STL namespace.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::makeTupleVector
constexpr auto makeTupleVector(T &&... t)
Definition tuplevector.hh:108
Dune::TupleVector
A class augmenting std::tuple by element access via operator[].
Definition tuplevector.hh:35
Dune::TupleVector::size
static constexpr std::size_t size()
Number of elements of the tuple.
Definition tuplevector.hh:76
Dune::TupleVector::TupleVector
constexpr TupleVector(TT &&... tt)
Construct from a set of arguments.
Definition tuplevector.hh:48
Dune::TupleVector::operator[]
constexpr decltype(auto) operator[](const Dune::index_constant< i > &) const
Const access to the tuple elements.
Definition tuplevector.hh:61
Dune::TupleVector::operator[]
constexpr decltype(auto) operator[](const Dune::index_constant< i > &)
Non-const access to the tuple elements.
Definition tuplevector.hh:70
Dune::TupleVector::TupleVector
constexpr TupleVector()
Default constructor.
Definition tuplevector.hh:54
std::tuple_element< i, Dune::TupleVector< Args... > >::type
typename std::tuple_element< i, std::tuple< Args... > >::type type
Definition tuplevector.hh:128