gcc/libstdc++-v3
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
..
config libstdc++: Fix bootstrap failure in atomicity.cc 2025-09-12 11:35:41 +01:00
doc libstdc++: Document remaining C++20 implementation-defined behavior. 2025-09-10 09:43:43 +02:00
include libstdc++: Reuse predicates in std::search and std::is_permutation 2025-09-26 11:05:59 +01:00
libsupc++ libstdc++: Make atomicity helpers use unsigned arithmetic [PR121148] 2025-09-11 14:43:55 +01:00
po Update copyright years. 2025-01-02 11:59:57 +01:00
python libsupc++: Change _Unordered comparison value to minimum value of signed char. 2025-08-27 14:50:20 +02:00
scripts libstdc++: Implement std::chrono::current_zone() for Windows [PR108409] 2025-07-15 16:49:43 +01:00
src libstdc++: Implement C++23 P2590R2 - Explicit lifetime management [PR106658] 2025-09-18 07:44:54 +02:00
testsuite libstdc++: Fix unsafe comma operators in <random> [PR122062] 2025-09-26 11:01:08 +01:00
.editorconfig libstdc++: editorconfig: Adjust wildcard patterns 2024-12-07 08:49:26 +00:00
ChangeLog Daily bump. 2025-09-26 00:20:03 +00:00
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013 Rotate ChangeLog files. 2025-01-02 11:06:31 +01:00
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
ChangeLog-2019
ChangeLog-2020
ChangeLog-2021
ChangeLog-2022 Rotate ChangeLog files. 2025-01-02 11:06:31 +01:00
ChangeLog-2023 Rotate ChangeLog files. 2025-01-02 11:06:31 +01:00
ChangeLog-2024 Rotate ChangeLog files. 2025-01-02 11:06:31 +01:00
Makefile.am Update copyright years. 2025-01-02 11:59:57 +01:00
Makefile.in libstdc++: Use -C option to run recursive make in sub-directories 2024-11-16 01:05:06 +00:00
README
acinclude.m4 libstdc++: Implement C++26 <debugging> features [PR119670] 2025-08-28 17:47:00 +01:00
aclocal.m4
config.h.in libstdc++: Implement C++26 <debugging> features [PR119670] 2025-08-28 17:47:00 +01:00
configure libstdc++: Implement C++26 <debugging> features [PR119670] 2025-08-28 17:47:00 +01:00
configure.ac libstdc++: Implement C++26 <debugging> features [PR119670] 2025-08-28 17:47:00 +01:00
configure.host GCN, nvptx libstdc++: Force use of '__atomic' builtins: revert 'atomicity_dir=cpu/generic/atomicity_builtins' hard-coding [PR119645]" 2025-05-12 15:48:12 +02:00
crossconfig.m4
fragment.am
linkage.m4

README

file: libstdc++-v3/README

New users may wish to point their web browsers to the file
index.html in the 'doc/html' subdirectory.  It contains brief
building instructions and notes on how to configure the library in
interesting ways.