CbmRoot
Loading...
Searching...
No Matches
CbmTypeTraits.h
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include <optional>
13#include <type_traits>
14
15namespace cbm::util
16{
20 template<auto What, auto... Sequence>
23 static constexpr bool value{((What == Sequence) || ...)};
24 };
25
26 template<auto... Args>
27 constexpr bool is_in_sequence_v = is_in_sequence<Args...>::value;
28
29
31 template<typename...>
32 struct is_all_same : std::false_type {
33 };
34
35 template<>
36 struct is_all_same<> : std::true_type {
37 };
38
39 template<typename T>
40 struct is_all_same<T> : std::true_type {
41 };
42
43 template<typename T>
44 struct is_all_same<T, T> : std::true_type {
45 };
46
47 template<typename T, typename... Args>
48 struct is_all_same<T, T, Args...> : is_all_same<T, Args...> {
49 };
50
51
54 template<auto... Values>
55 constexpr bool have_same_type_v = is_all_same<decltype(Values)...>::value;
56
57
58 // TODO: re-use in CbmYaml.h, bring other type traits from CbmYamlBaseTypes.h here
60 template<typename>
61 struct is_std_optional : std::false_type {
62 };
63
64 template<typename T>
65 struct is_std_optional<std::optional<T>> : std::true_type {
66 };
67
68 template<typename T>
70
71
75 template<typename T, class Class>
76 struct is_pointer_to : std::false_type {
77 };
78
79 template<class Class>
80 struct is_pointer_to<const Class*, Class> : std::true_type {
81 };
82
83 template<class Class>
84 struct is_pointer_to<Class*, Class> : std::true_type {
85 };
86
87 template<typename T, class Class>
89
90
91} // namespace cbm::util
constexpr bool is_pointer_to_v
constexpr bool have_same_type_v
Checks, if non-type parameter pack has the same type.
constexpr bool is_in_sequence_v
constexpr bool is_std_optional_v
Hash for CbmL1LinkKey.
Checks, if the types in a sequence are all the same.
Checks at the compile time, if the non-type template parameter is in a sequence of values.
static constexpr bool value
Checks, if the template argument is a const/non-const pointer of a type.
Checks, if a value is std::optional.