OGLplus  (0.59.0) a C++ wrapper for rendering APIs

mem_func_const.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MEM_FUNC_CONST_HPP
10 #define EAGINE_MEM_FUNC_CONST_HPP
11 
12 #include <utility>
13 
14 namespace eagine {
15 
18 template <typename T, T Ptr>
20 
23 template <typename RV, typename C, typename... P, RV (C::*Ptr)(P...)>
24 struct member_function_constant<RV (C::*)(P...), Ptr> {
25 
27  using pointer = RV (C::*)(P...);
28 
30  using free_pointer = RV (*)(C*, P...);
31 
33  using result_type = RV;
34 
36  using scope = C;
37 
39  using is_const = std::false_type;
40 
43  static constexpr auto get() noexcept -> pointer {
44  return Ptr;
45  }
46 
49  static auto free_func(C* c, P... a) -> RV {
50  return (c->*Ptr)(std::forward<P>(a)...);
51  }
52 
56  static auto make_free() noexcept -> free_pointer {
57  return &free_func;
58  }
59 };
60 
61 template <typename RV, typename C, typename... P, RV (C::*Ptr)(P...) const>
62 struct member_function_constant<RV (C::*)(P...) const, Ptr> {
63 
65  using pointer = RV (C::*)(P...) const;
66 
68  using free_pointer = RV (*)(const C*, P...);
69 
71  using result_type = RV;
72 
74  using scope = C;
75 
77  using is_const = std::true_type;
78 
81  static constexpr auto get() noexcept -> pointer {
82  return Ptr;
83  }
84 
87  static auto free_func(const C* c, P... a) -> RV {
88  return (c->*Ptr)(std::forward<P>(a)...);
89  }
90 
94  static auto make_free() noexcept -> free_pointer {
95  return &free_func;
96  }
97 };
98 
99 template <typename RV, typename C, typename... P, RV (C::*Ptr)(P...) noexcept>
100 struct member_function_constant<RV (C::*)(P...) noexcept, Ptr> {
101 
103  using pointer = RV (C::*)(P...) noexcept;
104 
106  using free_pointer = RV (*)(C*, P...) noexcept;
107 
109  using result_type = RV;
110 
112  using scope = C;
113 
115  using is_const = std::false_type;
116 
119  static constexpr auto get() noexcept -> pointer {
120  return Ptr;
121  }
122 
125  static auto free_func(C* c, P... a) noexcept -> RV {
126  return (c->*Ptr)(std::forward<P>(a)...);
127  }
128 
132  static auto make_free() noexcept -> free_pointer {
133  return &free_func;
134  }
135 };
136 
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> {
139 
141  using pointer = RV (C::*)(P...) const noexcept;
142 
144  using free_pointer = RV (*)(const C*, P...) noexcept;
145 
147  using result_type = RV;
148 
150  using scope = C;
151 
153  using is_const = std::true_type;
154 
157  static constexpr auto get() noexcept -> pointer {
158  return Ptr;
159  }
160 
163  static auto free_func(const C* c, P... a) noexcept -> RV {
164  return (c->*Ptr)(std::forward<P>(a)...);
165  }
166 
170  static auto make_free() noexcept -> free_pointer {
171  return &free_func;
172  }
173 };
174 
179 #define EAGINE_MEM_FUNC_T(CLASS, FUNC) \
180  ::eagine::member_function_constant<decltype(&CLASS::FUNC), &CLASS::FUNC>
181 
186 #define EAGINE_MEM_FUNC_C(CLASS, FUNC) \
187  EAGINE_MEM_FUNC_T(CLASS, FUNC) {}
188 
191 #define EAGINE_THIS_T() std::remove_cv_t<std::remove_pointer_t<decltype(this)>>
192 
197 #define EAGINE_THIS_MEM_FUNC_T(FUNC) \
198  ::eagine::member_function_constant< \
199  decltype(&EAGINE_THIS_T()::FUNC), \
200  &EAGINE_THIS_T()::FUNC>
201 
206 #define EAGINE_THIS_MEM_FUNC_C(FUNC) \
207  EAGINE_THIS_MEM_FUNC_T(FUNC) {}
208 
209 } // namespace eagine
210 
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

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).