alpaka
Abstraction Library for Parallel Kernel Acceleration
ForEachType.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Jan Stephan, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
8 
9 #include <utility>
10 
11 namespace alpaka::meta
12 {
13  namespace detail
14  {
15  template<typename TList>
17 
18  template<template<typename...> class TList>
19  struct ForEachTypeHelper<TList<>>
20  {
22  template<typename TFnObj, typename... TArgs>
23  ALPAKA_FN_HOST_ACC static auto forEachTypeHelper(TFnObj&& /* f */, TArgs&&... /* args */) -> void
24  {
25  }
26  };
27 
28  template<template<typename...> class TList, typename T, typename... Ts>
29  struct ForEachTypeHelper<TList<T, Ts...>>
30  {
32  template<typename TFnObj, typename... TArgs>
33  ALPAKA_FN_HOST_ACC static auto forEachTypeHelper(TFnObj&& f, TArgs&&... args) -> void
34  {
35  f.template operator()<T>(std::forward<TArgs>(args)...);
36  ForEachTypeHelper<TList<Ts...>>::forEachTypeHelper(
37  std::forward<TFnObj>(f),
38  std::forward<TArgs>(args)...);
39  }
40  };
41  } // namespace detail
42 
43  //! Equivalent to boost::mpl::for_each but does not require the types of the sequence to be default
44  //! constructible. This function does not create instances of the types instead it passes the types as template
45  //! parameter.
47  template<typename TList, typename TFnObj, typename... TArgs>
48  ALPAKA_FN_HOST_ACC auto forEachType(TFnObj&& f, TArgs&&... args) -> void
49  {
50  detail::ForEachTypeHelper<TList>::forEachTypeHelper(std::forward<TFnObj>(f), std::forward<TArgs>(args)...);
51  }
52 } // namespace alpaka::meta
#define ALPAKA_FN_HOST_ACC
Definition: Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto forEachType(TFnObj &&f, TArgs &&... args) -> void
Equivalent to boost::mpl::for_each but does not require the types of the sequence to be default const...
Definition: ForEachType.hpp:48
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC auto forEachTypeHelper(TFnObj &&f, TArgs &&... args) -> void
Definition: ForEachType.hpp:33
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC auto forEachTypeHelper(TFnObj &&, TArgs &&...) -> void
Definition: ForEachType.hpp:23