Files
gcc/libstdc++-v3/include/bits/predefined_ops.h

210 lines
6.3 KiB
C
Raw Normal View History

predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
// Default predicates for internal use -*- C++ -*-
2026-01-02 09:53:48 +01:00
// Copyright (C) 2013-2026 Free Software Foundation, Inc.
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file predefined_ops.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly. @headername{algorithm}
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
*/
#ifndef _GLIBCXX_PREDEFINED_OPS_H
#define _GLIBCXX_PREDEFINED_OPS_H 1
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
#include <bits/stl_function.h> // less<void>, equal_to<void>
#if __cplusplus >= 201103L
# include <type_traits> // is_empty, is_scalar, __conditional_t, __or_
#else
# include <ext/type_traits.h> // __conditional_type
#endif
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
namespace __gnu_cxx
{
namespace __ops
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
// These two explicit specializations are always defined by libstdc++,
// even when __cpp_lib_transparent_operators is not defined.
typedef std::equal_to<void> equal_to;
typedef std::less<void> less;
#if __cplusplus >= 201103L
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Fn>
using __by_ref_or_value_fn
= std::__conditional_t<std::__or_<std::is_empty<_Fn>,
std::is_scalar<_Fn>>::value,
_Fn, _Fn&>;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
// More generic replacements for the deprecated utilities
// std::bind1st, std::bind2nd, and std::not1.
// These aren't fully "transparent" like std::less<void> because they
// do not use perfect forwarding, everything is treated as an lvalue.
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value, bool _Val_2nd = false>
struct _Comp_with_val
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
using _Fn = __by_ref_or_value_fn<_Func>;
explicit constexpr
_Comp_with_val(_Fn __f, const _Value& __v)
: _M_f(__f), _M_val(__v) { }
[[__no_unique_address__]] _Fn _M_f;
const _Value& _M_val;
template<typename _Tp>
_GLIBCXX14_CONSTEXPR bool
operator()(_Tp&& __arg)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wc++17-extensions"
if constexpr (_Val_2nd)
return _M_f(__arg, _M_val);
else
return _M_f(_M_val, __arg);
#pragma GCC diagnostic pop
}
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
};
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value>
using _Comp_with_val_1st = _Comp_with_val<_Func, _Value, false>;
template<typename _Func, typename _Value>
using _Comp_with_val_2nd = _Comp_with_val<_Func, _Value, true>;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func>
struct _Unary_negate
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
using _Fn = __by_ref_or_value_fn<_Func>;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
explicit constexpr
_Unary_negate(_Fn __f) : _M_f(__f) { }
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
[[__no_unique_address__]] _Fn _M_f;
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Tp>
_GLIBCXX14_CONSTEXPR bool
operator()(_Tp&& __arg) { return !_M_f(__arg); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
};
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func>
constexpr _Unary_negate<_Func>
not1(_Func& __f)
{ return _Unary_negate<_Func>(__f); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
#else // <= C++11
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Fn>
struct __by_ref_or_value_fn
: __conditional_type<__is_empty(_Fn), _Fn, _Fn&>
{ };
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Fn>
struct __by_ref_or_value_fn<_Fn*>
{ typedef _Fn* __type; };
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
// We don't use std::binder1st, std::binder2nd, or std::unary_negate here
// because they require adaptable function objects, i.e. types with nested
// result_type and argument_type/first_argument_type/second_argument_type.
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value>
struct _Comp_with_val_1st
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
typedef typename __by_ref_or_value_fn<_Func>::__type _Fn;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
explicit
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
_Comp_with_val_1st(_Fn __f, const _Value& __v)
: _M_f(__f), _M_val(__v) { }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
_Fn _M_f;
const _Value& _M_val;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Tp>
bool operator()(_Tp& __arg) { return _M_f(_M_val, __arg); }
template<typename _Tp>
bool operator()(const _Tp& __arg) { return _M_f(_M_val, __arg); }
};
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value>
struct _Comp_with_val_2nd
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
typedef typename __by_ref_or_value_fn<_Func>::__type _Fn;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
explicit
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
_Comp_with_val_2nd(_Fn __f, const _Value& __v)
: _M_f(__f), _M_val(__v) { }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
_Fn _M_f;
const _Value& _M_val;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Tp>
bool operator()(_Tp& __arg) { return _M_f(__arg, _M_val); }
template<typename _Tp>
bool operator()(const _Tp& __arg) { return _M_f(__arg, _M_val); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
};
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func>
struct _Unary_negate_1 // N.B. different name for C++98 to satisfy ODR
{
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
typedef typename __by_ref_or_value_fn<_Func>::__type _Fn;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
explicit _Unary_negate_1(_Fn __f) : _M_f(__f) { }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
_Fn _M_f;
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Tp>
bool
operator()(_Tp& __arg) { return !_M_f(__arg); }
template<typename _Tp>
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
bool
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
operator()(const _Tp& __arg) { return !_M_f(__arg); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
};
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func>
inline _Unary_negate_1<_Func>
not1(_Func& __f)
{ return _Unary_negate_1<_Func>(__f); }
#endif
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
// N.B. these functions take lvalue references because we want to avoid
// returning a call wrapper that has a dangling reference to a prvalue.
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value>
_GLIBCXX_CONSTEXPR inline _Comp_with_val_1st<_Func, _Value>
bind1st(_Func& __f, const _Value& __val)
{ return _Comp_with_val_1st<_Func, _Value>(__f, __val); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
template<typename _Func, typename _Value>
_GLIBCXX_CONSTEXPR inline _Comp_with_val_2nd<_Func, _Value>
bind2nd(_Func& __f, const _Value& __val)
{ return _Comp_with_val_2nd<_Func, _Value>(__f, __val); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
libstdc++: Eliminate __gnu_cxx::__ops function objects This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-06-13 17:27:51 +01:00
// Equivalent to bind2nd(equal_to{}, val)
template<typename _Value>
_GLIBCXX_CONSTEXPR inline _Comp_with_val_2nd<equal_to, _Value>
__equal_to(const _Value& __val)
{ return _Comp_with_val_2nd<equal_to, _Value>(equal_to(), __val); }
predefined_ops.h: New. 2013-09-27 François Dumont <fdumont@gcc.gnu.org> * include/bits/predefined_ops.h: New. * include/bits/stl_heap.h: Include <bits/predefined_ops.h>. (__is_heap_until, __push_heap, __adjust_heap, __pop_heap): Remove algo duplication. (__is_heap): Adapt. (__make_heap): New. (make_heap): Adapt to use latter. (__sort_heap): New. (sort_heap): Adapt to use latter. * include/bits/algobase.h: Include <bits/predefined_ops.h>. (__lexicographical_compare_impl): New. (__lexicographical_compare<false>::__lc): Adapt to use latter. (lexicographical_compare): Likewise. (__lower_bound): New. (lower_bound): Adapt to use latter. (equal): Use _GLIBCXX_STD_A::equal in N3671 overloads. (__mismatch): New. (mismatch): Use latter. * include/bits/algo.h: Include <bits/predefined_ops.h>. Remove <functional> include. (__move_median_first, __find, __find_if, __find_if_not): Remove algo duplication. (__find_end): Likewise. (__search_n): Rename into ... (__search_n_aux): ... this. (__search_n): Renew, use latter. (search_n): Use latter. (__search): New. (search): Use latter. (__find_end): Likewise. (__remove_copy_if): New. (remove_copy): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__unique): New. (unique): Use latter. (__unique_copy): Remove algo duplication. (__stable_partition): New. (stable_partition): Use latter. (__heap_select): Remove algo duplication, use __make_heap. (__partial_sort): New, use latter. (partial_sort): Use latter. (__partial_sort_copy): New. (partial_sort_copy): Use latter. (__unguarded_linear_insert, __insertion_sort): Remove algo duplication. (__unguarded_insertion_sort, __final_insertion_sort): Likewise. (__unguarded_partition, __unguarded_partition_pivot): Likewise. (__partial_sort): New. (partial_sort): Use latter. (__sort): New. (sort): Use latter. (lower_bound): Use __lower_bound. (__upper_bound): New. (upper_bound): Use latter. (__equal_range): New. (equal_range): Use latter. (__move_merge_adaptive, __move_merge_adaptive_backward): Remove algo duplication. (__merge_adaptive, __merge_without_buffer): Likewise. (__inplace_merge): New. (inplace_merge): Use latter. (__move_merge, __merge_sort_loop, __chunk_insertion_sort): Remove algo duplication. (__merge_sort_with_buffer, __stable_sort_adaptive): Likewise. (__inplace_stable_sort): Likewise. (__include): New. (includes): Use latter. (__next_permutation): New. (next_permutation): Use latter. (__prev_permutation): New. (prev_permutation): Use latter. (__replace_copy_if): New. (replace_copy): Use latter. (__is_sorted_until): New. (is_sorted_unitl): Use latter. (__minmax_element): New. (minmax_element): Use latter. (__is_permutation): New. (is_permutation): Use latter. (__adjacent_find): New. (adjacent_find): Use latter. (__count_if): New. (count): Use latter. (count_if): Likewise. (__merge): New. (merge): Use latter. (__stable_sort): New. (stable_sort): Use latter. (__set_union): New. (set_union): Use latter. (__set_intersection): New. (set_intersection): Use latter. (__set_difference): New. (set_difference): Use latter. (__set_symmetric_difference): New. (set_symmetric_difference): Use latter. (__min_element): New. (min_element): Use latter. (__max_element): New. (max_element): Use latter. * include/Makefile.am: Add predefined_ops.h. * include/Makefile.in: Regenerate. * include/parallel/algobase.h (equal, mismatch): Add overloads from N3671. * testsuite/25_algorithms/is_permutation/vectorbool.cc: New. * testsuite/25_algorithms/adjacent_find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_first_of/vectorbool.cc: Likewise. * testsuite/25_algorithms/heap/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_end/vectorbool.cc: Likewise. * testsuite/25_algorithms/find_if_not/vectorbool.cc: Likewise. From-SVN: r202992
2013-09-27 21:17:36 +00:00
} // namespace __ops
} // namespace __gnu_cxx
#endif