libzypp: zypp-core/zyppng/meta/function_traits.h Source File

libzypp 17.36.6

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 >
26 struct function_traits;
27
28template<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
44template<class R, class... Args>
45 struct function_traits<R(*)(Args...)> : public function_traits<R(Args...)>
46{ };
47
48// function ref
49template<class R, class... Args>
50 struct function_traits<R(&)(Args...)> : public function_traits<R(Args...)>
51{ };
52
53// member function pointer
54template<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
59template<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
64template<class C, class R>
65 struct function_traits<R(C::*)> : public function_traits<R(C&)>
66{};
67
68template <typename T>
69 using has_call_operator = decltype (&T::operator());
70
71//functor with one overload
72template<class F>
73 struct function_traits<F, std::void_t<decltype (&F::operator())>> : public function_traits<decltype (&F::operator())>
74{};
75
76}
77#endif
std
Definition Arch.h:364
zyppng
Definition MediaCurl2.h:22
zyppng::has_call_operator
decltype(&T::operator()) has_call_operator
Definition function_traits.h:69
zyppng::function_traits< R(Args...)>::argument
Definition function_traits.h:37
zyppng::function_traits< R(Args...)>::argument::type
typename std::tuple_element< N, std::tuple< Args... > >::type type
Definition function_traits.h:39
zyppng::function_traits< R(Args...)>::return_type
R return_type
Definition function_traits.h:31
zyppng::function_traits< R(Args...)>::arity
static constexpr std::size_t arity
Definition function_traits.h:33
zyppng::function_traits
Definition function_traits.h:26