libzypp 17.37.17
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
23namespace zyppng {
24
25template<class F, class = void >
27
28template<class R, class... Args>
29struct 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
44template<class R, class... Args>
45struct function_traits<R(*)(Args...)> : public function_traits<R(Args...)>
46{ };
47
48// function ref
49template<class R, class... Args>
50struct function_traits<R(&)(Args...)> : public function_traits<R(Args...)>
51{ };
52
53// member function pointer
54template<class C, class R, class... Args>
55struct function_traits<R(C::*)(Args...)> : public function_traits<R(C&,Args...)>
56{};
57
58// const member function pointer, this will match lambdas too
59template<class C, class R, class... Args>
60struct function_traits<R(C::*)(Args...) const> : public function_traits<R(C&,Args...)>
61{};
62
63// member object pointer
64template<class C, class R>
65struct function_traits<R(C::*)> : public function_traits<R(C&)>
66{};
67
68template <typename T>
69using has_call_operator = decltype (&T::operator());
70
71//functor with one overload
72template<class F>
73struct function_traits<F, std::void_t<decltype (&F::operator())>> : public function_traits<decltype (&F::operator())>
74{};
75
76}
77#endif
Definition Arch.h:364
decltype(&T::operator()) has_call_operator
typename std::tuple_element< N, std::tuple< Args... > >::type type
static constexpr std::size_t arity