Go to the documentation of this file.
9 #ifndef EAGINE_MEM_FUNC_CONST_HPP
10 #define EAGINE_MEM_FUNC_CONST_HPP
18 template <
typename T, T Ptr>
23 template <
typename RV,
typename C,
typename... P, RV (C::*Ptr)(P...)>
50 return (c->*Ptr)(std::forward<P>(a)...);
61 template <
typename RV,
typename C,
typename... P, RV (C::*Ptr)(P...)
const>
62 struct member_function_constant<RV (C::*)(P...) const, Ptr> {
65 using pointer = RV (C::*)(P...)
const;
68 using free_pointer = RV (*)(
const C*, P...);
71 using result_type = RV;
77 using is_const = std::true_type;
81 static constexpr
auto get() noexcept -> pointer {
87 static auto free_func(
const C* c, P... a) -> RV {
88 return (c->*Ptr)(std::forward<P>(a)...);
94 static auto make_free() noexcept -> free_pointer {
99 template <
typename RV,
typename C,
typename... P, RV (C::*Ptr)(P...) noexcept>
100 struct member_function_constant<RV (C::*)(P...) noexcept, Ptr> {
103 using pointer = RV (C::*)(P...) noexcept;
106 using free_pointer = RV (*)(C*, P...) noexcept;
109 using result_type = RV;
115 using is_const = std::false_type;
119 static constexpr
auto get() noexcept -> pointer {
125 static auto free_func(C* c, P... a) noexcept -> RV {
126 return (c->*Ptr)(std::forward<P>(a)...);
132 static auto make_free() noexcept -> free_pointer {
137 template <
typename RV,
typename C,
typename... P, RV (C::*Ptr)(P...)
const noexcept>
138 struct member_function_constant<RV (C::*)(P...) const noexcept, Ptr> {
141 using pointer = RV (C::*)(P...)
const noexcept;
144 using free_pointer = RV (*)(
const C*, P...) noexcept;
147 using result_type = RV;
153 using is_const = std::true_type;
157 static constexpr
auto get() noexcept -> pointer {
163 static auto free_func(
const C* c, P... a) noexcept -> RV {
164 return (c->*Ptr)(std::forward<P>(a)...);
170 static auto make_free() noexcept -> free_pointer {
179 #define EAGINE_MEM_FUNC_T(CLASS, FUNC) \
180 ::eagine::member_function_constant<decltype(&CLASS::FUNC), &CLASS::FUNC>
186 #define EAGINE_MEM_FUNC_C(CLASS, FUNC) \
187 EAGINE_MEM_FUNC_T(CLASS, FUNC) {}
191 #define EAGINE_THIS_T() std::remove_cv_t<std::remove_pointer_t<decltype(this)>>
197 #define EAGINE_THIS_MEM_FUNC_T(FUNC) \
198 ::eagine::member_function_constant< \
199 decltype(&EAGINE_THIS_T()::FUNC), \
200 &EAGINE_THIS_T()::FUNC>
206 #define EAGINE_THIS_MEM_FUNC_C(FUNC) \
207 EAGINE_THIS_MEM_FUNC_T(FUNC) {}
211 #endif // EAGINE_MEM_FUNC_CONST_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
C scope
Alias for the class to which the member function belongs.
Definition: mem_func_const.hpp:36
std::false_type is_const
Alias for type indicating if the member function is const.
Definition: mem_func_const.hpp:39
static constexpr auto get() noexcept -> pointer
Returns the member function pointer.
Definition: mem_func_const.hpp:43
static auto make_free() noexcept -> free_pointer
Returns pointer to a free function corresponding to the member function.
Definition: mem_func_const.hpp:56
static auto free_func(C *c, P... a) -> RV
A function that calls the member function on an instance of C.
Definition: mem_func_const.hpp:49
Declaration of compile-time member function pointer wrappers.
Definition: mem_func_const.hpp:19
RV(C::*)(P...) pointer
Alias for the member function pointer type.
Definition: mem_func_const.hpp:27
RV result_type
Alias for the function result type.
Definition: mem_func_const.hpp:33
RV(*)(C *, P...) free_pointer
Alias for corresponding free function pointer type.
Definition: mem_func_const.hpp:30