abseil-cpp/absl/functional/internal/front_binder.h
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Implementation details for `absl::bind_front()`.
16 
17 #ifndef ABSL_FUNCTIONAL_INTERNAL_FRONT_BINDER_H_
18 #define ABSL_FUNCTIONAL_INTERNAL_FRONT_BINDER_H_
19 
20 #include <cstddef>
21 #include <type_traits>
22 #include <utility>
23 
24 #include "absl/base/internal/invoke.h"
25 #include "absl/container/internal/compressed_tuple.h"
26 #include "absl/meta/type_traits.h"
27 #include "absl/utility/utility.h"
28 
29 namespace absl {
31 namespace functional_internal {
32 
33 // Invoke the method, expanding the tuple of bound arguments.
34 template <class R, class Tuple, size_t... Idx, class... Args>
35 R Apply(Tuple&& bound, absl::index_sequence<Idx...>, Args&&... free) {
36  return base_internal::invoke(
37  absl::forward<Tuple>(bound).template get<Idx>()...,
38  absl::forward<Args>(free)...);
39 }
40 
41 template <class F, class... BoundArgs>
42 class FrontBinder {
44  using Idx = absl::make_index_sequence<sizeof...(BoundArgs) + 1>;
45 
47 
48  public:
49  template <class... Ts>
50  constexpr explicit FrontBinder(absl::in_place_t, Ts&&... ts)
51  : bound_args_(absl::forward<Ts>(ts)...) {}
52 
53  template <class... FreeArgs, class R = base_internal::invoke_result_t<
54  F&, BoundArgs&..., FreeArgs&&...>>
55  R operator()(FreeArgs&&... free_args) & {
56  return functional_internal::Apply<R>(bound_args_, Idx(),
57  absl::forward<FreeArgs>(free_args)...);
58  }
59 
60  template <class... FreeArgs,
62  const F&, const BoundArgs&..., FreeArgs&&...>>
63  R operator()(FreeArgs&&... free_args) const& {
64  return functional_internal::Apply<R>(bound_args_, Idx(),
65  absl::forward<FreeArgs>(free_args)...);
66  }
67 
68  template <class... FreeArgs, class R = base_internal::invoke_result_t<
69  F&&, BoundArgs&&..., FreeArgs&&...>>
70  R operator()(FreeArgs&&... free_args) && {
71  // This overload is called when *this is an rvalue. If some of the bound
72  // arguments are stored by value or rvalue reference, we move them.
73  return functional_internal::Apply<R>(absl::move(bound_args_), Idx(),
74  absl::forward<FreeArgs>(free_args)...);
75  }
76 
77  template <class... FreeArgs,
79  const F&&, const BoundArgs&&..., FreeArgs&&...>>
80  R operator()(FreeArgs&&... free_args) const&& {
81  // This overload is called when *this is an rvalue. If some of the bound
82  // arguments are stored by value or rvalue reference, we move them.
83  return functional_internal::Apply<R>(absl::move(bound_args_), Idx(),
84  absl::forward<FreeArgs>(free_args)...);
85  }
86 };
87 
88 template <class F, class... BoundArgs>
90 
91 } // namespace functional_internal
93 } // namespace absl
94 
95 #endif // ABSL_FUNCTIONAL_INTERNAL_FRONT_BINDER_H_
absl::decay_t
typename std::decay< T >::type decay_t
Definition: abseil-cpp/absl/meta/type_traits.h:628
absl::functional_internal::Apply
R Apply(Tuple &&bound, absl::index_sequence< Idx... >, Args &&... free)
Definition: abseil-cpp/absl/functional/internal/front_binder.h:35
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::functional_internal::FrontBinder::operator()
R operator()(FreeArgs &&... free_args) &
Definition: abseil-cpp/absl/functional/internal/front_binder.h:55
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
hpack_encoder_fixtures::Args
Args({0, 16384})
absl::make_index_sequence
make_integer_sequence< size_t, N > make_index_sequence
Definition: abseil-cpp/absl/utility/utility.h:150
absl::integer_sequence
Definition: abseil-cpp/absl/utility/utility.h:76
absl::functional_internal::FrontBinder::operator()
R operator()(FreeArgs &&... free_args) &&
Definition: abseil-cpp/absl/functional/internal/front_binder.h:70
absl::container_internal::CompressedTuple< F, BoundArgs... >
F
#define F(b, c, d)
Definition: md4.c:112
absl::functional_internal::FrontBinder::operator()
R operator()(FreeArgs &&... free_args) const &&
Definition: abseil-cpp/absl/functional/internal/front_binder.h:80
absl::functional_internal::FrontBinder::FrontBinder
constexpr FrontBinder(absl::in_place_t, Ts &&... ts)
Definition: abseil-cpp/absl/functional/internal/front_binder.h:50
absl::functional_internal::FrontBinder::operator()
R operator()(FreeArgs &&... free_args) const &
Definition: abseil-cpp/absl/functional/internal/front_binder.h:63
absl::functional_internal::FrontBinder
Definition: abseil-cpp/absl/functional/internal/front_binder.h:42
absl::functional_internal::FrontBinder::Idx
absl::make_index_sequence< sizeof...(BoundArgs)+1 > Idx
Definition: abseil-cpp/absl/functional/internal/front_binder.h:44
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::in_place_t
Definition: abseil-cpp/absl/utility/utility.h:174
absl::forward
constexpr T && forward(absl::remove_reference_t< T > &t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:230
absl::functional_internal::FrontBinder::bound_args_
BoundArgsT bound_args_
Definition: abseil-cpp/absl/functional/internal/front_binder.h:46
absl::base_internal::invoke_result_t
decltype(Invoker< F, Args... >::type::Invoke(std::declval< F >(), std::declval< Args >()...)) invoke_result_t
Definition: abseil-cpp/absl/base/internal/invoke.h:206
absl::base_internal::invoke
invoke_result_t< F, Args... > invoke(F &&f, Args &&... args)
Definition: abseil-cpp/absl/base/internal/invoke.h:211


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:25