alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
TypeListOps.hpp
Go to the documentation of this file.
1/* Copyright 2022 Bernhard Manfred Gruber
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include <tuple>
8#include <type_traits>
9
10namespace alpaka::meta
11{
12 namespace detail
13 {
14 template<typename List>
15 struct Front
16 {
17 };
18
19 template<template<typename...> class List, typename Head, typename... Tail>
20 struct Front<List<Head, Tail...>>
21 {
22 using type = Head;
23 };
24 } // namespace detail
25
26 template<typename List>
28
29 template<typename List, typename Value>
30 struct Contains : std::false_type
31 {
32 };
33
34 template<template<typename...> class List, typename Head, typename... Tail, typename Value>
35 struct Contains<List<Head, Tail...>, Value>
36 {
37 static constexpr bool value = std::is_same_v<Head, Value> || Contains<List<Tail...>, Value>::value;
38 };
39
40 // copied from https://stackoverflow.com/a/51073558/22035743
41 template<typename T>
42 struct IsList : std::false_type
43 {
44 };
45
46 template<template<typename...> class TList, typename... TTypes>
47 struct IsList<TList<TTypes...>> : std::true_type
48 {
49 };
50
51 //! \brief Checks whether the specified type is a list. List is a type with a variadic number of template types.
52 template<typename T>
53 constexpr bool isList = IsList<std::decay_t<T>>::value;
54
55 namespace detail
56 {
57 template<template<typename...> class TListType, typename TType, typename = void>
59 {
60 using type = TListType<TType>;
61 };
62
63 template<template<typename...> class TListType, typename TList>
64 struct ToListImpl<TListType, TList, std::enable_if_t<alpaka::meta::isList<TList>>>
65 {
66 using type = TList;
67 };
68 } // namespace detail
69
70 //! \brief Takes an arbitrary number of types (T) and creates a type list of type TListType with the types (T). If
71 //! T is a single template parameter and it satisfies alpaka::meta::isList, the type of the structure is T (no type
72 //! change). For example std::tuple can be used as TListType.
73 //! \tparam TListType type of the created list
74 //! \tparam T possible list types or type list
75 template<template<typename...> class TListType, typename... T>
76 struct ToList;
77
78 template<template<typename...> class TListType, typename T>
79 struct ToList<TListType, T> : detail::ToListImpl<TListType, T>
80 {
81 };
82
83 template<template<typename...> class TListType, typename T, typename... Ts>
84 struct ToList<TListType, T, Ts...>
85 {
86 using type = TListType<T, Ts...>;
87 };
88
89 //! \brief If T is a single argument and a type list (fullfil alpaka::meta::isList), the return type is T.
90 //! Otherwise, std::tuple is returned with T types as template parameters.
91 template<typename... T>
92 using ToTuple = typename ToList<std::tuple, T...>::type;
93
94
95} // namespace alpaka::meta
typename ToList< std::tuple, T... >::type ToTuple
If T is a single argument and a type list (fullfil alpaka::meta::isList), the return type is T....
constexpr bool isList
Checks whether the specified type is a list. List is a type with a variadic number of template types.
typename detail::Front< List >::type Front
STL namespace.
Takes an arbitrary number of types (T) and creates a type list of type TListType with the types (T)....