12#include "detray/utils/string_helpers.hpp"
13#include "detray/utils/tuple.hpp"
14#include "detray/utils/type_traits.hpp"
29template <
typename... Ts>
34template <
typename =
void>
37template <
typename... Ts>
39 : std::integral_constant<std::size_t, sizeof...(Ts)> {};
47template <
typename T, std::
size_t = 0,
typename =
void>
51template <
typename U, std::size_t I,
typename T,
typename... Ts>
56template <
typename T, std::size_t I,
typename... Ts>
59 static constexpr std::size_t
pos{I};
63template <
typename T, std::
size_t I>
66 static constexpr auto pos{std::numeric_limits<std::size_t>::max()};
69template <
typename L,
typename T>
70inline constexpr bool contains = contains_impl<T, 0u, L>::value;
72template <
typename L,
typename T>
73inline constexpr std::size_t position = contains_impl<T, 0u, L>::pos;
78template <
typename =
void>
82template <
typename T,
typename... Ts>
93template <
typename =
void>
97template <
typename T,
typename... Ts>
100 using type = std::conditional_t<
sizeof...(Ts) == 0, T,
116template <std::
size_t N,
typename =
void>
120template <std::size_t N,
typename T,
typename... Ts>
123 using type = std::remove_cvref_t<decltype(detray::get<N>(
126template <
typename L, std::
size_t N>
132template <
typename N,
typename =
void>
136template <
typename N,
typename... Ts>
141template <
typename L,
typename N>
147template <
typename N,
typename =
void>
151template <
typename N,
typename... Ts>
156template <
typename L,
typename N>
164template <
typename =
void>
167template <
typename... Ts>
183std::string demangle_type_name() {
184#if defined(__clang__)
185 constexpr std::string_view prefix{
"[T = "};
186 constexpr std::string_view suffix{
"]"};
187 constexpr std::string_view function{__PRETTY_FUNCTION__};
188#elif defined(__GNUC__)
189 constexpr std::string_view prefix{
"with T = "};
190 constexpr std::string_view suffix{
"; "};
191 constexpr std::string_view function{__PRETTY_FUNCTION__};
192#elif defined(_MSC_VER)
193 constexpr std::string_view prefix{
"get_type_name<"};
194 constexpr std::string_view suffix{
">(void)"};
195 constexpr std::string_view function{__FUNCSIG__};
197 std::string type_name{
typeid(
T).name()};
199 std::string_view function{type_name};
200 constexpr std::string_view prefix{
""};
201 constexpr std::string_view suffix{
" "};
204 const std::size_t start{function.find(prefix) + prefix.size()};
205 const std::size_t end{function.find(suffix)};
206 const std::size_t length{end - start};
208 return std::string{function.substr(start, length)};
214std::string get_name(
bool full =
false) {
215 std::string tp_str{
""};
217 tp_str = detray::types::demangle_type_name<T>();
222 if (tp_str.empty()) {
232 auto tokens = detray::utils::split_at_delim(tp_str,
'<');
233 tp_str = tokens.front();
239 tokens = detray::utils::split_at_delim(tp_str,
':');
240 return tokens.back();
244template <
typename =
void>
246 print() { std::puts(
"Not a type_list!\n"); }
250template <
typename... Ts>
254 template <
typename P = void,
typename... Ps>
256 std::printf(
"%s", get_name<P>(full).c_str());
259 if constexpr (
sizeof...(Ps) > 0) {
268 std::puts(
"type_list<");
286template <
typename orig_list_t,
class type_selector, std::size_t I = 0u,
288DETRAY_HOST_DEVICE
consteval auto filtered_list(
289 const list<Fs...>& filtered = list<>{}) {
290 static_assert(
sizeof...(Fs) <= I,
"Can only map down to list with ");
293 using list_t = list<Fs...>;
295 if constexpr (I == size<orig_list_t>) {
300 using next_type = at<orig_list_t, I>;
301 using mapped_t =
typename type_selector::template type<next_type>;
304 if constexpr (contains<list_t, mapped_t>) {
305 return filtered_list<orig_list_t, type_selector, I + 1u>(filtered);
307 return filtered_list<orig_list_t, type_selector, I + 1u>(
308 push_back<list_t, mapped_t>{});
325template <
typename orig_list_t,
class type_selector, std::size_t I = 0
u,
327DETRAY_HOST_DEVICE
consteval auto filtered_indices(
329 std::array<
dindex, size<orig_list_t>> idx_array = {0}) {
331 using list_t =
list<Fs...>;
333 if constexpr (I == size<orig_list_t>) {
338 using next_type = at<orig_list_t, I>;
339 using mapped_t =
typename type_selector::template type<next_type>;
342 if constexpr (contains<list_t, mapped_t>) {
343 idx_array[I] = position<list_t, mapped_t>;
345 return filtered_indices<orig_list_t, type_selector, I + 1u>(filtered,
348 idx_array[I] =
sizeof...(Fs);
350 return filtered_indices<orig_list_t, type_selector, I + 1u>(
351 push_back<list_t, mapped_t>{}, idx_array);
Definition type_list.hpp:363
constexpr double T
Magnetic field, native unit (eV*s)/(e*m²).
Definition Units.hpp:168
constexpr double u
atomic mass unit u
Definition Units.hpp:155
Type list concepts.
Definition concepts.hpp:17
Traits for the type list.
Definition type_list.hpp:162
constexpr bool is_type_list_v
Whether L is a types::list specialization.
Definition type_list.hpp:172
Detray include(s).
Definition array_operators.hpp:18
unsigned int dindex
Default index type.
Definition indexing.hpp:18
detray::tuple< types... > dtuple
Tuple type used by detray storage and dispatch.
Definition containers.hpp:46
static constexpr std::size_t pos
Zero-based position of the matching type.
Definition type_list.hpp:59
static constexpr auto pos
Sentinel position used when the type is absent.
Definition type_list.hpp:66
Does the list contain a particular type?
Definition type_list.hpp:48
Definition type_list.hpp:165
list< Ts..., N > type
Resulting type list.
Definition type_list.hpp:139
Append a type.
Definition type_list.hpp:133
list< N, Ts... > type
Resulting type list.
Definition type_list.hpp:154
Prepend a type.
Definition type_list.hpp:148
std::remove_cvref_t< decltype(detray::get< N >( std::declval< dtuple< T, Ts... > >()))> type
Type at position N.
Definition type_list.hpp:123
Access the N-th type.
Definition type_list.hpp:117
std::conditional_t< sizeof...(Ts)==0, T, typename get_back< list< Ts... > >::type > type
Last type in the list.
Definition type_list.hpp:100
void type
Type returned for an empty list.
Definition type_list.hpp:108
Access the last type.
Definition type_list.hpp:94
T type
First type in the list.
Definition type_list.hpp:85
Access the first type.
Definition type_list.hpp:79
Number of types in the list.
Definition type_list.hpp:35
type list implementation
Definition type_list.hpp:30
void print_typeid(bool full)
Print one type name and recursively print the remaining names.
Definition type_list.hpp:255
print(bool full=true)
Print the complete type list.
Definition type_list.hpp:267