distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
invoke.hpp
Go to the documentation of this file.
1 
12 #ifndef ESTD_INVOKE_HPP_
13 #define ESTD_INVOKE_HPP_
14 
15 #include <utility>
16 
17 namespace estd
18 {
19 
20 namespace internal
21 {
22 
35 template<typename Function, typename... Args>
36 inline auto invoke(Function&& function, Args&&... args) ->
37  decltype(std::forward<Function>(function)(std::forward<Args>(args)...))
38 {
39  return std::forward<Function>(function)(std::forward<Args>(args)...);
40 }
41 
57 template<typename T, typename Base, typename Derived, typename... Args>
58 inline auto invoke(T Base::* memberFunction, Derived&& object, Args&&... args) ->
59  decltype((std::forward<Derived>(object).*memberFunction)(std::forward<Args>(args)...))
60 {
61  return (std::forward<Derived>(object).*memberFunction)(std::forward<Args>(args)...);
62 }
63 
78 template<typename MemberFunction, typename Pointer, typename... Args>
79 inline auto invoke(MemberFunction memberFunction, Pointer&& pointer, Args&&... args) ->
80  decltype(((*std::forward<Pointer>(pointer)).*memberFunction)(std::forward<Args>(args)...))
81 {
82  return ((*std::forward<Pointer>(pointer)).*memberFunction)(std::forward<Args>(args)...);
83 }
84 
98 template<typename T, typename Base, typename Derived>
99 inline auto invoke(T Base::* dataMember, Derived&& object) -> decltype(std::forward<Derived>(object).*dataMember)
100 {
101  return std::forward<Derived>(object).*dataMember;
102 }
103 
116 template<typename DataMember, typename Pointer>
117 inline auto invoke(DataMember dataMember, Pointer&& pointer) -> decltype((*std::forward<Pointer>(pointer)).*dataMember)
118 {
119  return (*std::forward<Pointer>(pointer)).*dataMember;
120 }
121 
122 } // namespace internal
123 
138 template<typename Function, typename... Args>
139 inline auto invoke(Function&& function, Args&&... args) ->
140  decltype(internal::invoke(std::forward<Function>(function), std::forward<Args>(args)...))
141 {
142  return internal::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
143 }
144 
145 } // namespace estd
146 
147 #endif // ESTD_INVOKE_HPP_
Collection of useful templates.
auto invoke(Function &&function, Args &&... args) -> decltype(std::forward< Function >(function)(std::forward< Args >(args)...))
Implementation of invoke() for function objects.
Definition: invoke.hpp:36