Jonathan Wakely 1cf6cda055 libstdc++: Reuse predicates in std::search and std::is_permutation
Hoist construction of the call wrappers out of the loop when we're
repeatedly creating a call wrapper with the same bound arguments.

We need to be careful about iterators that return proxy references,
because bind1st(pred, *first) could bind a reference to a prvalue proxy
reference returned by *first. That would then be an invalid reference by
the time we invoked the call wrapper.

If we dereference the iterator first and store the result of that on the
stack, then we don't have a prvalue proxy reference, and can bind it (or
the value it refers to) into the call wrapper:

  auto&& val = *first; // lifetime extension
  auto wrapper = bind1st(pred, val);
  for (;;)
    /* use wrapper */;

This ensures that the reference returned from *first outlives the call
wrapper, whether it's a proxy reference or not.

For C++98 compatibility in __search we can use __decltype(expr) instead
of auto&&.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algobase.h (__search, __is_permutation):
	Reuse predicate instead of creating a new one each time.
	* include/bits/stl_algo.h (__is_permutation): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-26 11:05:59 +01:00
2025-08-11 00:16:52 +00:00
2025-09-24 00:21:37 +00:00
2025-08-29 00:19:55 +00:00
2025-08-17 00:19:17 +00:00
2025-09-24 00:21:37 +00:00
2025-09-26 00:20:03 +00:00
2025-09-06 00:20:34 +00:00
2025-09-03 00:20:18 +00:00
2025-09-20 00:20:23 +00:00
2025-09-19 00:20:17 +00:00
2025-08-06 00:21:26 +00:00
2025-08-17 00:19:17 +00:00
2025-09-08 00:20:50 +00:00
2025-09-02 00:19:26 +00:00
2025-09-24 00:21:37 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 2.7 GiB
Languages
C++ 30.7%
C 30.1%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.5%