Lely core libraries 2.3.5
invoker.hpp
Go to the documentation of this file.
1
21
22#ifndef LELY_UTIL_INVOKER_HPP_
23#define LELY_UTIL_INVOKER_HPP_
24
26#include <lely/libc/utility.hpp>
27
28#include <tuple>
29#include <utility>
30
31namespace lely {
32namespace util {
33
34namespace detail {
35
36template <class Tuple>
37class invoker {
38 Tuple tuple_;
39
40 template <::std::size_t... I>
41 auto
42 invoke_(compat::index_sequence<I...>) noexcept(
43 noexcept(compat::invoke(::std::get<I>(::std::move(tuple_))...)))
44 -> decltype(compat::invoke(::std::get<I>(::std::move(tuple_))...)) {
45 return compat::invoke(::std::get<I>(::std::move(tuple_))...);
46 }
47
48 using sequence_ =
50
51 public:
52 template <class F, class... Args,
53 class = typename ::std::enable_if<!::std::is_same<
54 typename ::std::decay<F>::type, invoker>::value>::type>
55 explicit invoker(F&& f, Args&&... args)
56 : tuple_{::std::forward<F>(f), ::std::forward<Args>(args)...} {}
57
58 auto
59 operator()() noexcept(
60 noexcept(::std::declval<invoker&>().invoke_(sequence_{})))
61 -> decltype(::std::declval<invoker&>().invoke_(sequence_{})) {
62 return invoke_(sequence_{});
63 }
64};
65
66} // namespace detail
67
72template <class F, class... Args>
73using invoker_t =
75 typename ::std::decay<Args>::type...>>;
76
81template <class F, class... Args>
82inline invoker_t<F, Args...>
83make_invoker(F&& f, Args&&... args) {
84 return invoker_t<F, Args...>{::std::forward<F>(f),
85 ::std::forward<Args>(args)...};
86}
87
88} // namespace util
89} // namespace lely
90
91#endif // !LELY_UTIL_INVOKER_HPP_
This header file is part of the compatibility library; it includes <functional> and defines any missi...
invoke_result_t< F, Args... > invoke(F &&f, Args &&... args)
Invokes f with the arguments args... as if by INVOKE(forward<F>(f), forward<Args>(args)....
invoker_t< F, Args... > make_invoker(F &&f, Args &&... args)
Creates a function object containing a Callable and its arguments.
Definition invoker.hpp:83
detail::invoker<::std::tuple< typename ::std::decay< F >::type, typename ::std::decay< Args >::type... > > invoker_t
A helper alias template for the result of lely::util::make_invoker<F, Args...>().
Definition invoker.hpp:73
This header file is part of the compatibility library; it includes <utility> and defines any missing ...
integer_sequence<::std::size_t, Ints... > index_sequence
A helper alias template for lely::compat::integer_sequence for the common case where T is std::size_t...
Definition utility.hpp:98
make_integer_sequence<::std::size_t, N > make_index_sequence
A helper alias template for make_integer_sequence for the common case where T is std::size_t.
Definition utility.hpp:113