distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
apply.hpp
Go to the documentation of this file.
1 
12 #ifndef ESTD_APPLY_HPP_
13 #define ESTD_APPLY_HPP_
14 
15 #include "estd/IntegerSequence.hpp"
16 #include "estd/invoke.hpp"
17 
18 #include <tuple>
19 
20 namespace estd
21 {
22 
23 namespace internal
24 {
25 
39 template<typename Function, typename Tuple, std::size_t... Indexes>
40 constexpr auto apply(Function&& function, Tuple&& tuple, estd::IndexSequence<Indexes...>) ->
41  decltype(estd::invoke(std::forward<Function>(function), std::get<Indexes>(std::forward<Tuple>(tuple))...))
42 {
43  return estd::invoke(std::forward<Function>(function), std::get<Indexes>(std::forward<Tuple>(tuple))...);
44 }
45 
46 } // namespace internal
47 
62 template <typename Function, typename Tuple>
63 constexpr auto apply(Function&& function, Tuple&& tuple) ->
64  decltype(internal::apply(std::forward<Function>(function), std::forward<Tuple>(tuple),
65  estd::MakeIndexSequence<std::tuple_size<typename std::decay<Tuple>::type>{}>{}))
66 {
67  return internal::apply(std::forward<Function>(function), std::forward<Tuple>(tuple),
68  estd::MakeIndexSequence<std::tuple_size<typename std::decay<Tuple>::type>{}>{});
69 }
70 
71 } // namespace estd
72 
73 #endif // ESTD_APPLY_HPP_
Collection of useful templates.
Definition: DmaChannel.hpp:121
MakeIntegerSequence< std::size_t, N > MakeIndexSequence
Generator of IndexSequence types.
Definition: IntegerSequence.hpp:212
Compile-time sequence of integers.
Definition: IntegerSequence.hpp:30
IntegerSequence template class header.
constexpr auto apply(Function &&function, Tuple &&tuple, estd::IndexSequence< Indexes... >) -> decltype(estd::invoke(std::forward< Function >(function), std::get< Indexes >(std::forward< Tuple >(tuple))...))
Implementation of apply()
Definition: apply.hpp:40
auto invoke(Function &&function, Args &&... args) -> decltype(internal::invoke(std::forward< Function >(function), std::forward< Args >(args)...))
Invokes callable object in an appropriate way.
Definition: invoke.hpp:139
constexpr auto apply(Function &&function, Tuple &&tuple) -> decltype(internal::apply(std::forward< Function >(function), std::forward< Tuple >(tuple), estd::MakeIndexSequence< std::tuple_size< typename std::decay< Tuple >::type >
Invokes callable object with a tuple of arguments.
Definition: apply.hpp:63
invoke() header