diff options
Diffstat (limited to 'absl/functional/bind_front.h')
-rw-r--r-- | absl/functional/bind_front.h | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/absl/functional/bind_front.h b/absl/functional/bind_front.h index 8448d7b3c121..5b47970e3577 100644 --- a/absl/functional/bind_front.h +++ b/absl/functional/bind_front.h @@ -38,9 +38,7 @@ ABSL_NAMESPACE_BEGIN // bind_front() // -// Binds the first N arguments of an invocable object and stores them by value, -// except types of `std::reference_wrapper` which are 'unwound' and stored by -// reference. +// Binds the first N arguments of an invocable object and stores them by value. // // Like `std::bind()`, `absl::bind_front()` is implicitly convertible to // `std::function`. In particular, it may be used as a simpler replacement for @@ -140,7 +138,9 @@ ABSL_NAMESPACE_BEGIN // // Example: Storing bound arguments by reference. // -// void Print(const string& a, const string& b) { LOG(INFO) << a << b; } +// void Print(const std::string& a, const std::string& b) { +// std::cerr << a << b; +// } // // std::string hi = "Hello, "; // std::vector<std::string> names = {"Chuk", "Gek"}; @@ -152,6 +152,24 @@ ABSL_NAMESPACE_BEGIN // // dangling references. // foo->DoInFuture(absl::bind_front(Print, std::ref(hi), "Guest")); // BAD! // auto f = absl::bind_front(Print, std::ref(hi), "Guest"); // BAD! +// +// Example: Storing reference-like types. +// +// void Print(absl::string_view a, const std::string& b) { +// std::cerr << a << b; +// } +// +// std::string hi = "Hello, "; +// // Copies "hi". +// absl::bind_front(Print, hi)("Chuk"); +// +// // Compile error: std::reference_wrapper<const string> is not implicitly +// // convertible to string_view. +// // absl::bind_front(Print, std::cref(hi))("Chuk"); +// +// // Doesn't copy "hi". +// absl::bind_front(Print, absl::string_view(hi))("Chuk"); +// template <class F, class... BoundArgs> constexpr functional_internal::bind_front_t<F, BoundArgs...> bind_front( F&& func, BoundArgs&&... args) { |