VCCC  2024.05
VisualCamp Common C++ library
bind_back.hpp
Go to the documentation of this file.
1 #ifndef VCCC_FUNCTIONAL_BIND_BACK_HPP_
2 #define VCCC_FUNCTIONAL_BIND_BACK_HPP_
3 
4 #include <cstddef>
5 #include <type_traits>
6 #include <utility>
7 
13 
14 namespace vccc {
15 namespace detail {
16 
17 template<typename F, typename... Args>
18 class bind_back_object : public bind_object_base<bind_back_object<F, Args...>, F, Args...> {
19  using base = bind_object_base<bind_back_object<F, Args...>, F, Args...>;
20  friend base;
21 
22  template<typename Self, typename... U>
23  struct bind_invoke_result
24  : invoke_result<copy_cvref_t<Self&&, F>, U&&..., copy_cvref_t<Self&&, Args>...> {};
25 
26  template<typename Self, typename... U>
27  struct bind_nothrow_invocable
28  : is_nothrow_invocable<copy_cvref_t<Self&&, F>, U&&..., copy_cvref_t<Self&&, Args>...> {};
29 
30  template<std::size_t...I, typename Self, typename... U>
31  static constexpr typename bind_invoke_result<Self&&, U&&...>::type
32  call(Self&& self, std::index_sequence<I...>, U&&... args) noexcept(bind_nothrow_invocable<Self&&, U&&...>::value) {
33  return vccc::invoke(
34  std::forward<Self>(self).func_,
35  std::forward<U>(args)...,
36  std::get<I>(std::forward<Self>(self).args_)...
37  );
38  }
39 
40  public:
41  using base::base;
42  using base::operator();
43 };
44 
45 } // namespace detail
46 
49 
50 template<typename F, typename... Args, std::enable_if_t<conjunction<
51  std::is_constructible<std::decay_t<F>, F>,
52  std::is_move_constructible<std::decay_t<F>>,
53  std::is_constructible<std::decay_t<Args>, Args>...,
54  std::is_move_constructible<std::decay_t<Args>>...
55 >::value, int> = 0>
56 constexpr auto bind_back(F&& f, Args&&... args) {
57  return detail::bind_back_object<std::decay_t<F>, std::decay_t<Args>...>{
58  detail::bind_object_ctor_tag{},
59  std::forward<F>(f),
60  std::forward<Args>(args)...
61  };
62 }
63 
65 
66 } // namespace vccc
67 
68 #endif // VCCC_FUNCTIONAL_BIND_BACK_HPP_
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr auto bind_back(F &&f, Args &&... args)
Definition: bind_back.hpp:56
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35