functional.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <functional>
12 #include <type_traits>
13 #include <utility>
14 
15 namespace cras
16 {
17 
18 // Shims for C++17-only std::invoke and std::apply.
19 
20 #if defined(__cpp_lib_invoke) && __cpp_lib_invoke >= 201411L && defined(__cpp_lib_apply) && __cpp_lib_apply >= 201603L
21 using ::std::invoke;
22 using ::std::invoke_result;
23 using ::std::invoke_result_t;
24 using ::std::is_invocable;
25 using ::std::is_invocable_r;
26 using ::std::apply;
27 #else
28 namespace impl
29 {
31 #include <cras_cpp_common/external/invoke.hpp/invoke.hpp>
33 }
34 using ::cras::impl::invoke_hpp::invoke;
35 using ::cras::impl::invoke_hpp::invoke_result;
36 using ::cras::impl::invoke_hpp::invoke_result_t;
37 using ::cras::impl::invoke_hpp::is_invocable;
38 using ::cras::impl::invoke_hpp::is_invocable_r;
39 using ::cras::impl::invoke_hpp::apply;
40 #endif
41 
42 // Shim for C++20 std::bind_front.
43 
44 #if defined(__cpp_lib_bind_front) && __cpp_lib_bind_front >= 201907L
45 using std::bind_front;
46 #else
47 template<class F, class...Args>
48 auto bind_front(F&& f, Args&&... args)
49 {
50  return [f = ::std::forward<F>(f), boundArgs = ::std::make_tuple(::std::forward<Args>(args)...)](auto&&... unboundArgs)
51  {
52  return ::cras::apply(
53  [&](auto&&... args) -> decltype(auto) {
54  return ::cras::invoke(f, decltype(args)(args)..., decltype(unboundArgs)(unboundArgs)...); },
55  boundArgs);
56  };
57 }
58 #endif
59 
60 }
f
auto bind_front(F &&f, Args &&... args)
Definition: functional.hpp:48
Definition: any.hpp:15


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53