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