ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
tuple.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef ESPRESSO_TUPLE_HPP
20#define ESPRESSO_TUPLE_HPP
21/**
22 * @file
23 * Algorithms for tuple-like inhomogeneous containers.
24 */
25
26#include "utils/get.hpp"
27#include "utils/type_traits.hpp"
28
29#include <cstddef>
30#include <tuple>
31#include <type_traits>
32#include <utility>
33
34namespace Utils {
35namespace detail {
36template <class Tuple, class F, std::size_t... I>
37constexpr void for_each_impl(F &&f, Tuple t, std::index_sequence<I...>) {
38 using expand = int[];
39 std::ignore = expand{0, ((void)(f(std::get<I>(t))), 0)...};
40}
41
42template <class F, class Tuple>
43constexpr void for_each_impl(F, Tuple, std::index_sequence<>) {}
44} // namespace detail
45
46template <class F, class Tuple> void for_each(F &&f, Tuple &t) {
47 detail::for_each_impl<Tuple &>(
48 std::forward<F>(f), t,
49 std::make_index_sequence<std::tuple_size<Tuple>::value>{});
50}
51
52template <class F, class Tuple> void for_each(F &&f, Tuple &&t) {
53 detail::for_each_impl(
54 std::forward<F>(f), std::forward<Tuple>(t),
55 std::make_index_sequence<
56 std::tuple_size<std::remove_reference_t<Tuple>>::value>{});
57}
58
59} // namespace Utils
60
61#endif // ESPRESSO_TUPLE_HPP
float f[3]
void for_each(F &&f, Tuple &t)
Definition tuple.hpp:46