alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
apply.hpp
Go to the documentation of this file.
1/* Copyright 2025 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8
9#include <utility>
10
11namespace alpaka
12{
13 namespace detail
14 {
15 template<typename T_Func, typename T_TupleLike, std::size_t... T_idx>
16 ALPAKA_FN_INLINE constexpr decltype(auto) applyImpl(
17 T_Func&& func,
18 T_TupleLike&& tuple,
19 std::index_sequence<T_idx...>)
20 {
21 using std::get;
22 return std::forward<T_Func>(func)(get<T_idx>(std::forward<T_TupleLike>(tuple))...);
23 }
24 } // namespace detail
25
26 /** Applies a function to the elements of a tuple-like object.
27 *
28 * This function forwards the function and the tuple-like object, and uses an index sequence to unpack the tuple.
29 *
30 * @param func The function to apply.
31 * @param tuple The tuple-like object containing the arguments for the function.
32 * @return The result of applying the function to the elements of the tuple-like object.
33 */
34 template<typename T_Func, typename T_TupleLike>
35 ALPAKA_FN_INLINE constexpr decltype(auto) apply(T_Func&& func, T_TupleLike&& tuple)
36 {
37 /** @attention Do not use std::tuple_size_v here because it results in compile issues with gcc11.4 */
38 return detail::applyImpl(
39 std::forward<T_Func>(func),
40 std::forward<T_TupleLike>(tuple),
41 std::make_index_sequence<std::tuple_size<std::decay_t<T_TupleLike>>::value>{});
42 }
43} // namespace alpaka
#define ALPAKA_FN_INLINE
Macro defining the inline function attribute.
Definition common.hpp:88
main alpaka namespace.
Definition alpaka.hpp:76
ALPAKA_FN_INLINE constexpr decltype(auto) apply(T_Func &&func, T_TupleLike &&tuple)
Applies a function to the elements of a tuple-like object.
Definition apply.hpp:35
constexpr decltype(auto) get(concepts::SpecializationOf< Dict > auto &t) noexcept
Definition Dict.hpp:156