Export of internal Abseil changes
-- 24162e64040e89f174531fa78fc0ff43c3a67da4 by Abseil Team <absl-team@google.com>: Make ABSL_RETIRED_FLAG behave consistently with ABSL_FLAG. Before the change: ABSL_RETIRED_FLAG does not compile when there are competing ctors in the type, even when ABSL_FLAG does. After the change: ABSL_RETIRED_FLAG compiles when ABSL_FLAG does. PiperOrigin-RevId: 286437395 -- 870d4cb4d114813e9cefe30d26d020b0fdcdc4b4 by Tom Manshreck <shreck@google.com>: Add docs on bind_front PiperOrigin-RevId: 286433540 -- b0c328bd9bb64e0382f942f93b85054229dafeac by Tom Manshreck <shreck@google.com>: Specify the format for LogSeverity flags PiperOrigin-RevId: 286402811 GitOrigin-RevId: 24162e64040e89f174531fa78fc0ff43c3a67da4 Change-Id: I89785145d049fee49c6b9cf3357893ece9a6231c
This commit is contained in:
parent
7bd1935dcb
commit
ad904b6cd3
5 changed files with 127 additions and 34 deletions
|
|
@ -11,17 +11,44 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// `absl::bind_front()` returns a functor by binding a number of arguments to
|
||||
// the front of a provided functor, allowing you to avoid known problems with
|
||||
// `std::bind()`. It is a form of partial function application
|
||||
// https://en.wikipedia.org/wiki/Partial_application.
|
||||
//
|
||||
// Like `std::bind()` it is implicitly convertible to `std::function`. In
|
||||
// particular, it may be used as a simpler replacement for `std::bind()` in most
|
||||
// cases, as it does not require placeholders to be specified. More
|
||||
// importantly, it provides more reliable correctness guarantees than
|
||||
// `std::bind()`.
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: bind_front.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// `absl::bind_front()` returns a functor by binding a number of arguments to
|
||||
// the front of a provided (usually more generic) functor. Unlike `std::bind`,
|
||||
// it does not require the use of argument placeholders. The simpler syntax of
|
||||
// `absl::bind_front()` allows you to avoid known misuses with `std::bind()`.
|
||||
//
|
||||
// `absl::bind_front()` is meant as a drop-in replacement for C++20's upcoming
|
||||
// `std::bind_front()`, which similarly resolves these issues with
|
||||
// `std::bind()`. Both `bind_front()` alternatives, unlike `std::bind()`, allow
|
||||
// partial function application. (See
|
||||
// https://en.wikipedia.org/wiki/Partial_application).
|
||||
|
||||
#ifndef ABSL_FUNCTIONAL_BIND_FRONT_H_
|
||||
#define ABSL_FUNCTIONAL_BIND_FRONT_H_
|
||||
|
||||
#include "absl/functional/internal/front_binder.h"
|
||||
#include "absl/utility/utility.h"
|
||||
|
||||
namespace absl {
|
||||
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.
|
||||
//
|
||||
// Like `std::bind()`, `absl::bind_front()` is implicitly convertible to
|
||||
// `std::function`. In particular, it may be used as a simpler replacement for
|
||||
// `std::bind()` in most cases, as it does not require placeholders to be
|
||||
// specified. More importantly, it provides more reliable correctness guarantees
|
||||
// than `std::bind()`; while `std::bind()` will silently ignore passing more
|
||||
// parameters than expected, for example, `absl::bind_front()` will report such
|
||||
// mis-uses as errors.
|
||||
//
|
||||
// absl::bind_front(a...) can be seen as storing the results of
|
||||
// std::make_tuple(a...).
|
||||
|
|
@ -125,19 +152,6 @@
|
|||
// // dangling references.
|
||||
// foo->DoInFuture(absl::bind_front(Print, std::ref(hi), "Guest")); // BAD!
|
||||
// auto f = absl::bind_front(Print, std::ref(hi), "Guest"); // BAD!
|
||||
|
||||
#ifndef ABSL_FUNCTIONAL_BIND_FRONT_H_
|
||||
#define ABSL_FUNCTIONAL_BIND_FRONT_H_
|
||||
|
||||
#include "absl/functional/internal/front_binder.h"
|
||||
#include "absl/utility/utility.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
// 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.
|
||||
template <class F, class... BoundArgs>
|
||||
constexpr functional_internal::bind_front_t<F, BoundArgs...> bind_front(
|
||||
F&& func, BoundArgs&&... args) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue