version 3.10-dev
partial.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_COMMON_PARTIAL_HH
13#define DUMUX_COMMON_PARTIAL_HH
14
15#include <tuple>
16#include <type_traits>
17
18#include <dune/istl/multitypeblockvector.hh>
19
20namespace Dumux {
21
27template<class ...Args, std::size_t ...i>
28auto partial(Dune::MultiTypeBlockVector<Args...>& v, Dune::index_constant<i>... indices)
29{
30 return Dune::MultiTypeBlockVector<std::add_lvalue_reference_t<std::decay_t<std::tuple_element_t<indices, std::tuple<Args...>>>>...>(v[indices]...);
31}
32
38template<class ...Args, std::size_t ...i>
39auto partial(const Dune::MultiTypeBlockVector<Args...>& v, Dune::index_constant<i>... indices)
40{
41 return Dune::MultiTypeBlockVector<std::add_lvalue_reference_t<const std::decay_t<std::tuple_element_t<indices, std::tuple<Args...>>>>...>(v[indices]...);
42}
43
49template<class ...Args, std::size_t ...i>
50auto partial(std::tuple<Args...>& v, Dune::index_constant<i>... indices)
51{
52 return std::tuple<std::add_lvalue_reference_t<std::decay_t<std::tuple_element_t<indices, std::tuple<Args...>>>>...>(std::get<indices>(v)...);
53}
54
60template<class ...Args, std::size_t ...i>
61auto partial(const std::tuple<Args...>& v, Dune::index_constant<i>... indices)
62{
63 return std::tuple<std::add_lvalue_reference_t<const std::decay_t<std::tuple_element_t<indices, std::tuple<Args...>>>>...>(std::get<indices>(v)...);
64}
65
71template<class T, std::size_t ...i>
72auto partial(T& t, std::tuple<Dune::index_constant<i>...> indices)
73{
74 return partial(t, Dune::index_constant<i>{}...);
75}
76
77} // end namespace Dumux
78
79#endif
Definition: variablesbackend.hh:34
Definition: adapt.hh:17
auto partial(Dune::MultiTypeBlockVector< Args... > &v, Dune::index_constant< i >... indices)
a function to get a MultiTypeBlockVector with references to some entries of another MultiTypeBlockVec...
Definition: partial.hh:28