timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
function_traits.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25#pragma once
26
27#if defined(__GNUC__) && (__GNUC__ >= 7) && (__cplusplus < 201703L)
28# pragma GCC diagnostic push
29# pragma GCC diagnostic ignored "-Wnoexcept-type"
30# pragma GCC diagnostic ignored "-Wignored-attributes"
31#elif defined(__GNUC__) && (__GNUC__ >= 6)
32# pragma GCC diagnostic push
33# pragma GCC diagnostic ignored "-Wignored-attributes"
34#endif
35
36#include <functional>
37#include <tuple>
38#include <type_traits>
39
40namespace tim
41{
42namespace mpl
43{
44//--------------------------------------------------------------------------------------//
45//
46// Function traits
47//
48//--------------------------------------------------------------------------------------//
49
50template <typename T>
52
53template <typename R, typename... Args>
54struct function_traits<std::function<R(Args...)>>
55{
56 static constexpr bool is_memfun = false;
57 static constexpr bool is_const = false;
58 static constexpr size_t nargs = sizeof...(Args);
59 using result_type = R;
60 using args_type = std::tuple<Args...>;
61 using call_type = args_type;
62};
63
64template <typename R, typename... Args>
65struct function_traits<R (*)(Args...)>
66{
67 static constexpr bool is_memfun = false;
68 static constexpr bool is_const = false;
69 static constexpr size_t nargs = sizeof...(Args);
70 using result_type = R;
71 using args_type = std::tuple<Args...>;
73};
74
75template <typename R, typename... Args>
76struct function_traits<R(Args...)>
77{
78 static constexpr bool is_memfun = false;
79 static constexpr bool is_const = false;
80 static constexpr size_t nargs = sizeof...(Args);
81 using result_type = R;
82 using args_type = std::tuple<Args...>;
84};
85
86// member function pointer
87template <typename C, typename R, typename... Args>
88struct function_traits<R (C::*)(Args...)>
89{
90 static constexpr bool is_memfun = true;
91 static constexpr bool is_const = false;
92 static constexpr size_t nargs = sizeof...(Args);
93 using result_type = R;
94 using args_type = std::tuple<Args...>;
95 using call_type = std::tuple<C&, Args...>;
96};
97
98// const member function pointer
99template <typename C, typename R, typename... Args>
100struct function_traits<R (C::*)(Args...) const>
101{
102 static constexpr bool is_memfun = true;
103 static constexpr bool is_const = true;
104 static constexpr size_t nargs = sizeof...(Args);
105 using result_type = R;
106 using args_type = std::tuple<Args...>;
107 using call_type = std::tuple<C&, Args...>;
108};
109
110// member object pointer
111template <typename C, typename R>
112struct function_traits<R(C::*)>
113{
114 static constexpr bool is_memfun = true;
115 static constexpr bool is_const = false;
116 static const size_t nargs = 0;
117 using result_type = R;
118 using args_type = std::tuple<>;
119 using call_type = std::tuple<C&>;
120};
121
122#if __cplusplus >= 201703L
123
124template <typename R, typename... Args>
125struct function_traits<std::function<R(Args...) noexcept>>
126{
127 static constexpr bool is_memfun = false;
128 static constexpr bool is_const = false;
129 static constexpr size_t nargs = sizeof...(Args);
130 using result_type = R;
131 using args_type = std::tuple<Args...>;
132 using call_type = args_type;
133};
134
135template <typename R, typename... Args>
136struct function_traits<R (*)(Args...) noexcept>
137{
138 static constexpr bool is_memfun = false;
139 static constexpr bool is_const = false;
140 static constexpr size_t nargs = sizeof...(Args);
141 using result_type = R;
142 using args_type = std::tuple<Args...>;
143 using call_type = args_type;
144};
145
146template <typename R, typename... Args>
147struct function_traits<R(Args...) noexcept>
148{
149 static constexpr bool is_memfun = false;
150 static constexpr bool is_const = false;
151 static constexpr size_t nargs = sizeof...(Args);
152 using result_type = R;
153 using args_type = std::tuple<Args...>;
154 using call_type = args_type;
155};
156
157// member function pointer
158template <typename C, typename R, typename... Args>
159struct function_traits<R (C::*)(Args...) noexcept>
160{
161 static constexpr bool is_memfun = true;
162 static constexpr bool is_const = false;
163 static constexpr size_t nargs = sizeof...(Args);
164 using result_type = R;
165 using args_type = std::tuple<Args...>;
166 using call_type = std::tuple<C&, Args...>;
167};
168
169// const member function pointer
170template <typename C, typename R, typename... Args>
171struct function_traits<R (C::*)(Args...) const noexcept>
172{
173 static constexpr bool is_memfun = true;
174 static constexpr bool is_const = true;
175 static constexpr size_t nargs = sizeof...(Args);
176 using result_type = R;
177 using args_type = std::tuple<Args...>;
178 using call_type = std::tuple<C&, Args...>;
179};
180
181#endif
182//
183} // namespace mpl
184} // namespace tim
185
186#if defined(__GNUC__) && (__GNUC__ >= 7) && (__cplusplus < 201703L)
187# pragma GCC diagnostic pop
188#elif defined(__GNUC__) && (__GNUC__ >= 6)
189# pragma GCC diagnostic pop
190#endif
STL namespace.
Definition: kokkosp.cpp:39