libzypp  17.36.1
function_traits.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 * //Code based on a blogpost on https://functionalcpp.wordpress.com/2013/08/05/function-traits/
14 *
15 */
16 #ifndef ZYPPNG_META_FUNCTION_TRAITS_H_INCLUDED
17 #define ZYPPNG_META_FUNCTION_TRAITS_H_INCLUDED
18 
19 #include <cstddef>
20 #include <tuple>
21 #include <zypp-core/zyppng/meta/TypeTraits>
22 
23 namespace zyppng {
24 
25 template<class F, class = void >
27 
28 template<class R, class... Args>
29 struct function_traits<R(Args...)>
30 {
31  using return_type = R;
32 
33  static constexpr std::size_t arity = sizeof...(Args);
34 
35  template <std::size_t N>
36  struct argument
37  {
38  static_assert(N >= 0 && N < arity, "error: invalid parameter index.");
39  using type = typename std::tuple_element<N,std::tuple<Args...>>::type;
40  };
41 };
42 
43 // function pointer
44 template<class R, class... Args>
45 struct function_traits<R(*)(Args...)> : public function_traits<R(Args...)>
46 { };
47 
48 // function ref
49 template<class R, class... Args>
50 struct function_traits<R(&)(Args...)> : public function_traits<R(Args...)>
51 { };
52 
53 // member function pointer
54 template<class C, class R, class... Args>
55 struct function_traits<R(C::*)(Args...)> : public function_traits<R(C&,Args...)>
56 {};
57 
58 // const member function pointer, this will match lambdas too
59 template<class C, class R, class... Args>
60 struct function_traits<R(C::*)(Args...) const> : public function_traits<R(C&,Args...)>
61 {};
62 
63 // member object pointer
64 template<class C, class R>
65 struct function_traits<R(C::*)> : public function_traits<R(C&)>
66 {};
67 
68 template <typename T>
69 using has_call_operator = decltype (&T::operator());
70 
71 //functor with one overload
72 template<class F>
73 struct function_traits<F, std::void_t<decltype (&F::operator())>> : public function_traits<decltype (&F::operator())>
74 {};
75 
76 }
77 #endif
typename std::tuple_element< N, std::tuple< Args... > >::type type
typename make_void< Ts... >::type void_t
Definition: type_traits.h:12
decltype(&T::operator()) has_call_operator
Definition: Arch.h:363