ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
type_traits.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/indexing.hpp"
13
14// System include(s)
15#include <limits>
16#include <type_traits>
17
18namespace detray::detail {
19
22template <typename T>
25 using type = T;
26};
27
29template <typename T>
30struct get_value_type<T*> {
32 using type = T;
33};
34
36template <typename container_t>
37 requires(!std::same_as<typename std::remove_cvref_t<container_t>::value_type,
38 void>)
41 using type = typename std::remove_cvref_t<container_t>::value_type;
42};
43
44template <typename T>
45using get_value_t = typename get_value_type<T>::type;
47
50template <typename first_t = void, typename... other_t>
51struct first_type {
53 using type = first_t;
54};
55
56template <typename... TYPES>
57using first_t = typename first_type<TYPES...>::type;
58
60template <std::size_t first_t, std::size_t... other_t>
61struct first_idx {
63 static constexpr std::size_t value = first_t;
64};
65
66template <std::size_t... TYPES>
67inline constexpr std::size_t first_idx_v = first_idx<TYPES...>::value;
69
72template <typename T, typename... Ts>
79 template <typename first_t, typename... remaining_types>
80 DETRAY_HOST_DEVICE static constexpr std::size_t type_pos_back() {
81 if constexpr (!std::is_same_v<T, first_t>) {
82 return type_pos_back<remaining_types...>();
83 }
84 if constexpr (std::is_same_v<T, first_t>) {
85 return sizeof...(remaining_types) + 1;
86 }
87 return std::numeric_limits<std::size_t>::max();
88 }
89
91 static constexpr std::size_t value = sizeof...(Ts) - type_pos_back<Ts...>();
92};
93
94template <typename T, typename... Ts>
95inline constexpr std::size_t get_type_pos_v = get_type_pos<T, Ts...>::value;
97
98} // namespace detray::detail
Extract the first value from an index pack.
Definition type_traits.hpp:61
static constexpr std::size_t value
The first index in the pack.
Definition type_traits.hpp:63
Extract the first type from a parameter pack.
Definition type_traits.hpp:51
first_t type
The first type in the pack, or void for an empty pack.
Definition type_traits.hpp:53
Get the position of a type in a template parameter pack.
Definition type_traits.hpp:73
static constexpr std::size_t type_pos_back()
Unroll a parameter pack without using a tuple to find T.
Definition type_traits.hpp:80
static constexpr std::size_t value
Zero-based position of T in Ts....
Definition type_traits.hpp:91
T type
The pointee type.
Definition type_traits.hpp:32
typename std::remove_cvref_t< container_t >::value_type type
The container's value type.
Definition type_traits.hpp:41
Extract the value type of e.g.
Definition type_traits.hpp:23
T type
The type itself when the argument is not a container or pointer.
Definition type_traits.hpp:25