TrinityCore
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 Types_h__
19#define Types_h__
20
21#include <type_traits>
22
23namespace Trinity
24{
25 // end "iterator" tag for find_type_if
26 struct find_type_end;
27
28 template<template<typename...> typename Check, typename... Ts>
30
31 template<template<typename...> typename Check>
32 struct find_type_if<Check>
33 {
34 using type = find_type_end;
35 };
36
37 template<template<typename...> typename Check, typename T1, typename... Ts>
38 struct find_type_if<Check, T1, Ts...> : std::conditional_t<Check<T1>::value, std::type_identity<T1>, find_type_if<Check, Ts...>>
39 {
40 };
41
42 /*
43 Utility to find a type matching predicate (Check) in a given type list (Ts)
44 Evaluates to first type matching predicate or find_type_end
45 Check must be a type that contains static bool ::value, _v aliases don't work
46
47 template<typename... Ts>
48 struct Example
49 {
50 using TupleArg = Trinity::find_type_if_t<Trinity::is_tuple, Ts...>;
51
52 bool HasTuple()
53 {
54 return !std::is_same_v<TupleArg, Trinity::find_type_end>;
55 }
56 };
57
58 Example<int, std::string, std::tuple<int, int, int>, char> example;
59 example.HasTuple() == true; // TupleArg is std::tuple<int, int, int>
60
61 Example<int, std::string, char> example2;
62 example2.HasTuple() == false; // TupleArg is Trinity::find_type_end
63 */
64 template<template<typename...> typename Check, typename... Ts>
65 using find_type_if_t = typename find_type_if<Check, Ts...>::type;
66
67 template <typename T>
68 struct dependant_false { static constexpr bool value = false; };
69
70 template <typename T>
72}
73
74#endif // Types_h__
typename find_type_if< Check, Ts... >::type find_type_if_t
Definition: Types.h:65
constexpr bool dependant_false_v
Definition: Types.h:71
static constexpr bool value
Definition: Types.h:68