DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
apply_n.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: apply_n.hpp
5// Author: crdrisko
6// Date: 11/21/2020-10:35:11
7// Description: An algorithm, based off std::apply, that only applies a function to the first N elements of a tuple
8
9#ifndef DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_META_TYPES_TUPLES_TUPLEALGORITHMS_APPLY_N_HPP
10#define DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_META_TYPES_TUPLES_TUPLEALGORITHMS_APPLY_N_HPP
11
12#include <cstddef>
13#include <tuple>
14#include <utility>
15
17
18namespace CppUtils::Meta
19{
30 template<std::size_t N, typename F, typename Tuple>
31 constexpr decltype(auto) apply_n(F&& f, Tuple&& tuple)
32 {
33 return std::apply(std::forward<F>(f), select(std::forward<Tuple>(tuple), std::make_index_sequence<N> {}));
34 }
35} // namespace CppUtils::Meta
36
37#endif
Definition frontList.hpp:13
constexpr decltype(auto) apply_n(F &&f, Tuple &&tuple)
Definition apply_n.hpp:31
constexpr auto select(const std::tuple< Elements... > &tuple, std::index_sequence< Indices... >)
Definition select.hpp:27