Ginkgo: ginkgo/core/synthesizer/containers.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
containers.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
6#define GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
7
8
9#include <array>
10#include <type_traits>
11
12
13namespace gko {
19 namespace syn {
20
21
28template <typename T, T... Values>
29 struct value_list {};
30
31
37template <typename... Types>
38 struct type_list {};
39
40
48template <int Start, int End, int Step = 1>
49 struct range {};
50
51
52namespace detail {
53
54
61template <typename List1, typename List2>
62struct concatenate_impl;
63
71template <typename T, T... Values1, T... Values2>
72struct concatenate_impl<value_list<T, Values1...>, value_list<T, Values2...>> {
73 using type = value_list<T, Values1..., Values2...>;
74};
75
76
77} // namespace detail
78
79
86template <typename List1, typename List2>
87 using concatenate = typename detail::concatenate_impl<List1, List2>::type;
88
89
90namespace detail {
91
92
98template <typename T, typename = void>
99struct as_list_impl;
100
107template <typename T, T... Values>
108struct as_list_impl<value_list<T, Values...>> {
109 using type = value_list<T, Values...>;
110};
111
117template <typename... Types>
118struct as_list_impl<type_list<Types...>> {
119 using type = type_list<Types...>;
120};
121
130template <int Start, int End, int Step>
131struct as_list_impl<range<Start, End, Step>, std::enable_if_t<(Start < End)>> {
132 using type = concatenate<
133 value_list<int, Start>,
134 typename as_list_impl<range<Start + Step, End, Step>>::type>;
135};
136
144template <int Start, int End, int Step>
145struct as_list_impl<range<Start, End, Step>, std::enable_if_t<(Start >= End)>> {
146 using type = value_list<int>;
147};
148
149
150} // namespace detail
151
152
159template <typename T>
160 using as_list = typename detail::as_list_impl<T>::type;
161
162
174template <typename T, T... Value>
175 constexpr std::array<T, sizeof...(Value)> as_array(value_list<T, Value...> vl)
176{
177 return std::array<T, sizeof...(Value)>{Value...};
178}
179
180
181} // namespace syn
182} // namespace gko
183
184
185#endif // GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
gko::syn
The Synthesizer namespace.
Definition containers.hpp:19
gko::syn::as_list
typename detail::as_list_impl< T >::type as_list
as_list<T> gives the alias type of as_list_impl<T>::type.
Definition containers.hpp:160
gko::syn::as_array
constexpr std::array< T, sizeof...(Value)> as_array(value_list< T, Value... > vl)
as_array<T> returns the array from value_list.
Definition containers.hpp:175
gko::syn::concatenate
typename detail::concatenate_impl< List1, List2 >::type concatenate
concatenate combines two value_list into one value_list.
Definition containers.hpp:87
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std
STL namespace.
gko::syn::range
range records start, end, step in template
Definition containers.hpp:49
gko::syn::type_list
type_list records several types in template
Definition containers.hpp:38
gko::syn::value_list
value_list records several values with the same type in template.
Definition containers.hpp:29