Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
function_traits.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <functional>
19 #include <type_traits>
20 
21 // Type traits class for functions.
22 // Allows to query result and argument types of free and member functions as
23 // well as of operator() of functors.
24 
25 namespace tc {
26 
27 template <typename T>
28 struct function_traits : public function_traits<decltype(&T::operator())> {};
29 
30 #define FUNCTION_TRAITS_STRUCT_BODY \
31  typedef R result_type; \
32  \
33  template <size_t i> \
34  struct arg { \
35  typedef typename std::tuple_element<i, std::tuple<Args...>>::type type; \
36  }; \
37  \
38  typedef std::tuple<Args...> packed_args_type; \
39  typedef R (*c_function_type)(Args...); \
40  constexpr static size_t n_args = sizeof...(Args)
41 
42 template <typename ClassType, typename R, typename... Args>
43 struct function_traits<R (ClassType::*)(Args...) const> {
45  constexpr static bool is_member = true;
46  constexpr static bool is_static_member = true;
47  typedef ClassType class_type;
48 };
49 
50 template <typename R, typename... Args>
51 struct function_traits<R (*)(Args...)> {
53  constexpr static bool is_member = false;
54 };
55 
56 } // namespace tc
Definition: function_traits.h:28
ClassType class_type
Definition: function_traits.h:47
FUNCTION_TRAITS_STRUCT_BODY
Definition: function_traits.h:52
FUNCTION_TRAITS_STRUCT_BODY
Definition: function_traits.h:44