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
23
namespace
Trinity
24
{
25
// end "iterator" tag for find_type_if
26
struct
find_type_end;
27
28
template
<
template
<
typename
...>
typename
Check,
typename
... Ts>
29
struct
find_type_if
;
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>
71
constexpr
bool
dependant_false_v
=
dependant_false<T>::value
;
72
}
73
74
#endif
// Types_h__
Trinity
Definition:
AsioHacksFwd.h:58
Trinity::find_type_if_t
typename find_type_if< Check, Ts... >::type find_type_if_t
Definition:
Types.h:65
Trinity::dependant_false_v
constexpr bool dependant_false_v
Definition:
Types.h:71
Trinity::dependant_false
Definition:
Types.h:68
Trinity::dependant_false::value
static constexpr bool value
Definition:
Types.h:68
Trinity::find_type_if< Check >::type
find_type_end type
Definition:
Types.h:34
Trinity::find_type_if
Definition:
Types.h:29
common
Utilities
Types.h
Generated on Tue Sep 17 2024 20:04:42 for TrinityCore by
1.9.4