Low-Level Abstraction of Memory Access
Meta.hpp
Go to the documentation of this file.
1 // Copyright 2022 Bernhard Manfred Gruber
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #pragma once
5 
6 #include "macros.hpp"
7 
8 #include <boost/mp11.hpp>
9 
10 namespace llama
11 {
12  // make mp11 directly available in the llama namespace
13  using namespace boost::mp11;
14 
15  namespace internal
16  {
17  // adapted from boost::mp11, but with LLAMA_FN_HOST_ACC_INLINE
18  template<template<typename...> typename L, typename... T, typename F>
19  // NOLINTNEXTLINE(readability-identifier-naming)
20  LLAMA_FN_HOST_ACC_INLINE constexpr void mp_for_each_inline_impl(L<T...>, F&& f)
21  {
22  using A = int[sizeof...(T)];
23  (void) A{((void) f(T{}), 0)...};
24  }
25 
26  template<typename FromList, template<auto...> class ToList>
28 
29  template<template<class...> class FromList, typename... Values, template<auto...> class ToList>
30  struct mp_unwrap_values_into_impl<FromList<Values...>, ToList>
31  {
32  using type = ToList<Values::value...>;
33  };
34 
35  template<typename FromList, template<auto...> class ToList>
37 
38  template<typename E, typename... Args>
40  {
41  using type = E;
42  };
43  template<std::size_t I, typename... Args>
44  struct ReplacePlaceholdersImpl<mp_arg<I>, Args...>
45  {
46  using type = mp_at_c<mp_list<Args...>, I>;
47  };
48 
49  template<template<typename...> typename E, typename... Ts, typename... Args>
50  struct ReplacePlaceholdersImpl<E<Ts...>, Args...>
51  {
52  using type = E<typename ReplacePlaceholdersImpl<Ts, Args...>::type...>;
53  };
54  } // namespace internal
55 
57  template<typename L, typename F>
58  // NOLINTNEXTLINE(readability-identifier-naming)
60  {
61  internal::mp_for_each_inline_impl(mp_rename<L, mp_list>{}, std::forward<F>(f));
62  }
63 
65  template<typename Expression, typename... Args>
66  using ReplacePlaceholders = typename internal::ReplacePlaceholdersImpl<Expression, Args...>::type;
67 } // namespace llama
#define LLAMA_EXPORT
Definition: macros.hpp:192
#define LLAMA_FN_HOST_ACC_INLINE
Definition: macros.hpp:96
typename mp_unwrap_values_into_impl< FromList, ToList >::type mp_unwrap_values_into
Definition: Meta.hpp:36
constexpr void mp_for_each_inline_impl(L< T... >, F &&f)
Definition: Meta.hpp:20
typename internal::ReplacePlaceholdersImpl< Expression, Args... >::type ReplacePlaceholders
Definition: Meta.hpp:66
constexpr void mp_for_each_inline(F &&f)
Like boost::mp11::mp_for_each, but marked with LLAMA_FN_HOST_ACC_INLINE.
Definition: Meta.hpp:59
E< typename ReplacePlaceholdersImpl< Ts, Args... >::type... > type
Definition: Meta.hpp:52