Lely core libraries 2.3.4
c_call.hpp
Go to the documentation of this file.
1// NOLINT(legal/copyright)
54#ifndef LELY_UTIL_C_CALL_HPP_
55#define LELY_UTIL_C_CALL_HPP_
56
57#include <lely/util/util.h>
58
59namespace lely {
60
61template <class, class>
63
64template <class, class>
65struct c_mem_fn;
66template <class F, class C, typename c_mem_fn<F, C>::type>
68
69namespace impl {
70
71template <class...>
72struct c_pack;
73
74template <class, class>
77template <class T, class... S>
78struct c_pack_push_front<T, c_pack<S...>> {
79 using type = c_pack<T, S...>;
80};
81
83template <class T, class... S>
85 : c_pack_push_front<T, typename c_pack_pop_back<S...>::type> {};
87template <class T, class S>
88struct c_pack_pop_back<T, S> {
89 using type = c_pack<T>;
90};
91
92} // namespace impl
93
98template <class R, class... ArgTypes, class F>
99struct c_obj_call<impl::c_pack<R, ArgTypes...>, F> {
100 static R
101 function(ArgTypes... args, void* data) noexcept {
102 return (*static_cast<F*>(data))(args...);
103 }
104};
105
110template <class R, class... ArgTypes, class F>
111struct c_obj_call<R (*)(ArgTypes...), F>
112 : c_obj_call<typename impl::c_pack_pop_back<R, ArgTypes...>::type, F> {};
113
118template <class R, class... ArgTypes, class C>
119struct c_mem_fn<impl::c_pack<R, ArgTypes...>, C> {
120 using type = R (C::*)(ArgTypes...);
121};
122
127template <class R, class... ArgTypes, class C>
128struct c_mem_fn<R (*)(ArgTypes...), C>
129 : c_mem_fn<typename impl::c_pack_pop_back<R, ArgTypes...>::type, C> {};
130
135template <class R, class... ArgTypes, class C,
136 typename c_mem_fn<impl::c_pack<R, ArgTypes...>, C>::type M>
137struct c_mem_call<impl::c_pack<R, ArgTypes...>, C, M> {
138 static R
139 function(ArgTypes... args, void* data) noexcept {
140 return ((*static_cast<C*>(data)).*M)(args...);
141 }
142};
143
148template <class R, class... ArgTypes, class C,
149 typename c_mem_fn<R (*)(ArgTypes...), C>::type M>
150struct c_mem_call<R (*)(ArgTypes...), C, M>
151 : c_mem_call<typename impl::c_pack_pop_back<R, ArgTypes...>::type, C, M> {};
152
153} // namespace lely
154
155#endif // !LELY_UTIL_C_CALL_HPP_
This is the public header file of the utilities library.
Pops a type from the back of a parameter pack.
Definition: c_call.hpp:85