gem5 v24.0.0.0
Loading...
Searching...
No Matches
type_traits.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Arteris, Inc. and its applicable licensors and
3 * affiliates.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef BASE_TYPETRAITS_HH
31#define BASE_TYPETRAITS_HH
32
33#include <tuple>
34#include <type_traits>
35
36namespace gem5
37{
38
39/*
40 * Type traits that enable inspecting the signature of a member function based
41 * on a pointer to that function. Specifically, these type traits provide a
42 * class_t, a return_t and a argsTuple_t alias that correspond respectively to
43 * the class that the function is a member of, the return type of the member
44 * function and the list of parameters types packed in a tuple. Convenience
45 * Convenience template aliases are also provided.
46 *
47 * Example, assuming "struct Struct {void foo(int, bool);};":
48 * - MemberFunctionClass_t<&Struct::foo> is Struct.
49 * - MemberFunctionReturn_t<&Struct::foo> is void.
50 * - MemberFunctionArgsTuple_t<&Struct::foo> is std::tuple<int, bool>.
51 */
52
53template<typename F>
55template<typename C, typename R, class... A>
56struct MemberFunctionSignature<R(C::*)(A...)>
57{
58 using class_t = C;
59 using return_t = R;
60 using argsTuple_t = std::tuple<A...>;
61};
62template<typename C, typename R, class... A>
63struct MemberFunctionSignature<R(C::*)(A...) const>
64{
65 using class_t = std::add_const_t<C>;
66 using return_t = R;
67 using argsTuple_t = std::tuple<A...>;
68};
69template<typename C, typename R, class... A>
70struct MemberFunctionSignature<R(C::*)(A...) volatile>
71{
72 using class_t = std::add_volatile_t<C>;
73 using return_t = R;
74 using argsTuple_t = std::tuple<A...>;
75};
76template<typename C, typename R, class... A>
77struct MemberFunctionSignature<R(C::*)(A...) const volatile>
78{
79 using class_t = std::add_cv_t<C>;
80 using return_t = R;
81 using argsTuple_t = std::tuple<A...>;
82};
83template<auto F>
85 typename MemberFunctionSignature<decltype(F)>::class_t;
86
87template<auto F>
89 typename MemberFunctionSignature<decltype(F)>::return_t;
90
91template<auto F>
93 typename MemberFunctionSignature<decltype(F)>::argsTuple_t;
94
95
96// iterable type trait
97template <typename, typename = void>
98struct is_iterable: std::false_type {};
99
100template <typename T>
101struct is_iterable<T,
102 std::void_t<decltype(begin(std::declval<T>())),
103 decltype(end(std::declval<T>()))>>: std::true_type {};
104
105template <typename T>
107
108// std::hash-enabled type trait
109template <typename, typename = void>
110struct is_std_hash_enabled: std::false_type {};
111
112template <typename T>
114 std::void_t<decltype(std::hash<T>())>>: std::true_type {};
115
116template <typename T>
118
119} // namespace gem5
120
121#endif // BASE_TYPETRAITS_HH
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
constexpr bool is_iterable_v
typename MemberFunctionSignature< decltype(F)>::class_t MemberFunctionClass_t
typename MemberFunctionSignature< decltype(F)>::argsTuple_t MemberFunctionArgsTuple_t
typename MemberFunctionSignature< decltype(F)>::return_t MemberFunctionReturn_t
constexpr bool is_std_hash_enabled_v
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0