libfilezilla
apply.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_APPLY_HEADER
2 #define LIBFILEZILLA_APPLY_HEADER
3 
4 #include <utility>
5 #include <tuple>
6 #include <type_traits>
7 
16 namespace fz {
17 
21 template<typename F, typename Tuple, size_t... I>
22 auto apply_(F&& f, Tuple&& t, std::index_sequence<I...> const&) -> decltype(std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...))
23 {
24  return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
25 }
26 
42 template<typename F, typename Tuple, typename Seq = typename std::make_index_sequence<std::tuple_size<typename std::remove_reference<Tuple>::type>::value>>
43 auto apply(F && f, Tuple&& args) -> decltype(apply_(std::forward<F>(f), std::forward<Tuple>(args), Seq()))
44 {
45  return apply_(std::forward<F>(f), std::forward<Tuple>(args), Seq());
46 }
47 
51 template<typename Obj, typename F, typename Tuple, size_t... I>
52 auto apply_(Obj&& obj, F&& f, Tuple&& t, std::index_sequence<I...> const&) -> decltype((std::forward<Obj>(obj)->*std::forward<F>(f))(std::get<I>(std::forward<Tuple>(t))...))
53 {
54  return (std::forward<Obj>(obj)->*std::forward<F>(f))(std::get<I>(std::forward<Tuple>(t))...);
55 }
56 
76 template<typename Obj, typename F, typename Tuple, typename Seq = typename std::make_index_sequence<std::tuple_size<typename std::remove_reference<Tuple>::type>::value>>
77 auto apply(Obj&& obj, F && f, Tuple&& args) -> decltype(apply_(std::forward<Obj>(obj), std::forward<F>(f), std::forward<Tuple>(args), Seq()))
78 {
79  return apply_(std::forward<Obj>(obj), std::forward<F>(f), std::forward<Tuple>(args), Seq());
80 }
81 
82 }
83 
84 #endif
auto apply(F &&f, Tuple &&args) -> decltype(apply_(std::forward< F >(f), std::forward< Tuple >(args), Seq()))
Apply tuple to ordinary functor.
Definition: apply.hpp:43
The namespace used by libfilezilla.
Definition: apply.hpp:16