TrinityCore
Loading...
Searching...
No Matches
Types.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_TYPES_H
19#define TRINITYCORE_TYPES_H
20
21#include <type_traits>
22
23namespace Trinity
24{
25 template <bool HasType, typename T>
27 {
28 static constexpr bool has_type = HasType;
29 using type = T;
30 };
31
32 template <typename T>
33 struct find_type_result<false, T>
34 {
35 static constexpr bool has_type = false;
36 };
37
38 namespace Impl
39 {
40 template <template <typename> typename Check, typename T, typename... Ts>
42 {
43 if constexpr (Check<T>::value)
45 else if constexpr (sizeof...(Ts) == 0)
47 else
48 return find_type_in_list_if_impl<Check, Ts...>();
49 }
50 }
51
52 /*
53 Utility to find a type matching predicate (Check) in a given type list (Ts)
54 Evaluates to Trinity::find_type_result
55 Check must be a type that contains static bool ::value, _v aliases don't work
56
57 using Example1 = Trinity::find_type_in_list_if<Trinity::is_tuple, int, std::string, std::tuple<int, int, int>, char>;
58 Example1::has_type == true; // Example1::type is Trinity::find_type_result<true, std::tuple<int, int, int>>
59
60 using Example2 = Trinity::find_type_in_list_if<Trinity::is_tuple, int, std::string, char>;
61 Example1::has_type == false; // Example2::type is not defined
62 */
63 template<template<typename...> typename Check, typename... Ts>
64 using find_type_in_list_if = decltype(Impl::find_type_in_list_if_impl<Check, Ts...>());
65
66 template <typename T, typename... Us>
67 constexpr bool has_type_in_list_v = std::disjunction_v<std::is_same<T, Us>...>;
68
69 template <typename T>
70 struct dependant_false { static constexpr bool value = false; };
71
72 template <typename T>
74}
75
76#endif // TRINITYCORE_TYPES_H
consteval auto find_type_in_list_if_impl()
Definition Types.h:41
constexpr bool has_type_in_list_v
Definition Types.h:67
decltype(Impl::find_type_in_list_if_impl< Check, Ts... >()) find_type_in_list_if
Definition Types.h:64
constexpr bool dependant_false_v
Definition Types.h:73
static constexpr bool value
Definition Types.h:70
static constexpr bool has_type
Definition Types.h:28