Nui
function_traits.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace Nui
4 {
5  namespace Detail
6  {
7  // Helper for obtaining the argument types of a function
8  template <typename Functor, typename ReturnT, typename... Rest>
9  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (Functor::*)(Rest...));
10  template <typename Functor, typename ReturnT, typename... Rest>
11  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (Functor::*)(Rest...) const);
12  template <typename ReturnT, typename... Rest>
13  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (*)(Rest...));
14 
15  template <typename Functor, typename ReturnT, typename... Rest>
16  ReturnT FunctionInferenceHelperRet(ReturnT (Functor::*)(Rest...));
17  template <typename Functor, typename ReturnT, typename... Rest>
18  ReturnT FunctionInferenceHelperRet(ReturnT (Functor::*)(Rest...) const);
19  template <typename ReturnT, typename... Rest>
20  ReturnT FunctionInferenceHelperRet(ReturnT (*)(Rest...));
21 
22  // noexcept
23  template <typename Functor, typename ReturnT, typename... Rest>
24  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (Functor::*)(Rest...) noexcept);
25  template <typename Functor, typename ReturnT, typename... Rest>
26  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (Functor::*)(Rest...) const noexcept);
27  template <typename ReturnT, typename... Rest>
28  std::tuple<Rest...> FunctionInferenceHelper(ReturnT (*)(Rest...) noexcept);
29 
30  template <typename Functor, typename ReturnT, typename... Rest>
31  ReturnT FunctionInferenceHelperRet(ReturnT (Functor::*)(Rest...) noexcept);
32  template <typename Functor, typename ReturnT, typename... Rest>
33  ReturnT FunctionInferenceHelperRet(ReturnT (Functor::*)(Rest...) const noexcept);
34  template <typename ReturnT, typename... Rest>
35  ReturnT FunctionInferenceHelperRet(ReturnT (*)(Rest...) noexcept);
36 
37  // Allows to get the argument types of a function.
38  template <typename FunctionT>
40  {
41  using type = decltype(FunctionInferenceHelper(&FunctionT::operator()));
42  using return_type = decltype(FunctionInferenceHelperRet(&FunctionT::operator()));
43  };
44  template <typename FunctorT, typename ReturnT, typename... Arguments>
45  struct FunctionTypesImpl<ReturnT (FunctorT::*)(Arguments...)>
46  {
47  using return_type = ReturnT;
48  using type = std::tuple<Arguments...>;
49  };
50  template <typename FunctorT, typename ReturnT, typename... Arguments>
51  struct FunctionTypesImpl<ReturnT (FunctorT::*)(Arguments...) const>
52  {
53  using return_type = ReturnT;
54  using type = std::tuple<Arguments...>;
55  };
56  template <typename ReturnT, typename... Arguments>
57  struct FunctionTypesImpl<ReturnT (*)(Arguments...)>
58  {
59  using return_type = ReturnT;
60  using type = std::tuple<Arguments...>;
61  };
62 
63  // noexcept
64  template <typename FunctorT, typename ReturnT, typename... Arguments>
65  struct FunctionTypesImpl<ReturnT (FunctorT::*)(Arguments...) noexcept>
66  {
67  using return_type = ReturnT;
68  using type = std::tuple<Arguments...>;
69  };
70  template <typename FunctorT, typename ReturnT, typename... Arguments>
71  struct FunctionTypesImpl<ReturnT (FunctorT::*)(Arguments...) const noexcept>
72  {
73  using return_type = ReturnT;
74  using type = std::tuple<Arguments...>;
75  };
76  template <typename ReturnT, typename... Arguments>
77  struct FunctionTypesImpl<ReturnT (*)(Arguments...) noexcept>
78  {
79  using return_type = ReturnT;
80  using type = std::tuple<Arguments...>;
81  };
82  }
83 
84  template <typename FunctionT>
86  {
88  };
89 
90  template <typename FunctionT>
92  {
94  };
95 
96  template <typename T>
98  template <typename T>
100 }
std::tuple< Rest... > FunctionInferenceHelper(ReturnT(Functor::*)(Rest...))
ReturnT FunctionInferenceHelperRet(ReturnT(Functor::*)(Rest...))
Definition: file_dialog.hpp:6
typename FunctionArgumentTypes< T >::type FunctionArgumentTypes_t
Definition: function_traits.hpp:97
typename FunctionReturnType< T >::type FunctionReturnType_t
Definition: function_traits.hpp:99
std::tuple< Arguments... > type
Definition: function_traits.hpp:54
std::tuple< Arguments... > type
Definition: function_traits.hpp:74
std::tuple< Arguments... > type
Definition: function_traits.hpp:68
std::tuple< Arguments... > type
Definition: function_traits.hpp:48
std::tuple< Arguments... > type
Definition: function_traits.hpp:80
std::tuple< Arguments... > type
Definition: function_traits.hpp:60
ReturnT return_type
Definition: function_traits.hpp:59
Definition: function_traits.hpp:40
decltype(FunctionInferenceHelper(&FunctionT::operator())) type
Definition: function_traits.hpp:41
decltype(FunctionInferenceHelperRet(&FunctionT::operator())) return_type
Definition: function_traits.hpp:42
Definition: function_traits.hpp:86
typename Detail::FunctionTypesImpl< std::decay_t< FunctionT > >::type type
Definition: function_traits.hpp:87
Definition: function_traits.hpp:92
typename Detail::FunctionTypesImpl< std::decay_t< FunctionT > >::return_type type
Definition: function_traits.hpp:93