Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Constrained algorithms(since C++20)

      From cppreference.com
      <cpp‎ |algorithm
       
       
      Algorithm library
      Constrained algorithms and algorithms on ranges(C++20)
      Constrained algorithms, e.g.ranges::copy,ranges::sort, ...
      Execution policies(C++17)
      Sorting and related operations
      Partitioning operations
      Sorting operations
      Binary search operations
      (on partitioned ranges)
      Set operations (on sorted ranges)
      Merge operations (on sorted ranges)
      Heap operations
      Minimum/maximum operations
      (C++11)
      (C++17)
      Lexicographical comparison operations
      Permutation operations
      C library
      Numeric operations
      Operations on uninitialized memory
       
      Constrained algorithms
      All names in this menu belong to namespacestd::ranges
      Non-modifying sequence operations
      Modifying sequence operations
      Partitioning operations
      Sorting operations
      Binary search operations (on sorted ranges)
             
             
      Set operations (on sorted ranges)
      Heap operations
      Minimum/maximum operations
      Permutation operations
      Fold operations
      Operations on uninitialized storage
      Return types
       

      C++20 providesconstrained versions of most algorithms in the namespacestd::ranges. In these algorithms, a range can be specified as either aniterator-sentinel pair or as a singlerange argument, and projections and pointer-to-member callables are supported. Additionally, thereturn types of most algorithms have been changed to return all potentially useful information computed during the execution of the algorithm.

      Contents

      [edit]Algorithm function objects

      Analgorithm function object (AFO), informally known asniebloid, is acustomization point object (CPO) that is specified as one or more overloaded function templates. The name of these function templates designates the corresponding algorithm function object.

      For an algorithm function objecto, letS be the corresponding set of function templates. Then for any sequence of argumentsargs...,o(args...) isexpression-equivalent tos(args...), where the result of name lookup fors is the overload setS.

      The constrained algorithms in the namespacestd::ranges are defined as algorithm function objects. As a result:

      [edit]Constrained algorithms

      Defined in header<algorithm>
      Defined in namespacestd::ranges
      Non-modifying sequence operations
      checks if a predicate istrue for all, any or none of the elements in a range
      (algorithm function object)[edit]
      applies a unaryfunction object to elements from arange
      (algorithm function object)[edit]
      applies a function object to the first N elements of a sequence
      (algorithm function object)[edit]
      returns the number of elements satisfying specific criteria
      (algorithm function object)[edit]
      finds the first position where two ranges differ
      (algorithm function object)[edit]
      determines if two sets of elements are the same
      (algorithm function object)[edit]
      returnstrue if one range is lexicographically less than another
      (algorithm function object)[edit]
      finds the first element satisfying specific criteria
      (algorithm function object)[edit]
      finds the last element satisfying specific criteria
      (algorithm function object)[edit]
      finds the last sequence of elements in a certain range
      (algorithm function object)[edit]
      searches for any one of a set of elements
      (algorithm function object)[edit]
      finds the first two adjacent items that are equal (or satisfy a given predicate)
      (algorithm function object)[edit]
      searches for the first occurrence of a range of elements
      (algorithm function object)[edit]
      searches for the first occurrence of a number consecutive copies of an element in a range
      (algorithm function object)[edit]
      checks if the range contains the given element or subrange
      (algorithm function object)[edit]
      checks whether a range starts with another range
      (algorithm function object)[edit]
      checks whether a range ends with another range
      (algorithm function object)[edit]
      Modifying sequence operations
      copies a range of elements to a new location
      (algorithm function object)[edit]
      copies a number of elements to a new location
      (algorithm function object)[edit]
      copies a range of elements in backwards order
      (algorithm function object)[edit]
      moves a range of elements to a new location
      (algorithm function object)[edit]
      moves a range of elements to a new location in backwards order
      (algorithm function object)[edit]
      assigns a range of elements a certain value
      (algorithm function object)[edit]
      assigns a value to a number of elements
      (algorithm function object)[edit]
      applies a function to a range of elements
      (algorithm function object)[edit]
      saves the result of a function in a range
      (algorithm function object)[edit]
      saves the result of N applications of a function
      (algorithm function object)[edit]
      removes elements satisfying specific criteria
      (algorithm function object)[edit]
      copies a range of elements omitting those that satisfy specific criteria
      (algorithm function object)[edit]
      replaces all values satisfying specific criteria with another value
      (algorithm function object)[edit]
      copies a range, replacing elements satisfying specific criteria with another value
      (algorithm function object)[edit]
      swaps two ranges of elements
      (algorithm function object)[edit]
      reverses the order of elements in a range
      (algorithm function object)[edit]
      creates a copy of a range that is reversed
      (algorithm function object)[edit]
      rotates the order of elements in a range
      (algorithm function object)[edit]
      copies and rotate a range of elements
      (algorithm function object)[edit]
      randomly re-orders elements in a range
      (algorithm function object)[edit]
      shifts elements in a range
      (algorithm function object)[edit]
      selects N random elements from a sequence
      (algorithm function object)[edit]
      removes consecutive duplicate elements in a range
      (algorithm function object)[edit]
      creates a copy of some range of elements that contains no consecutive duplicates
      (algorithm function object)[edit]
      Partitioning operations
      determines if the range is partitioned by the given predicate
      (algorithm function object)[edit]
      divides a range of elements into two groups
      (algorithm function object)[edit]
      copies a range dividing the elements into two groups
      (algorithm function object)[edit]
      divides elements into two groups while preserving their relative order
      (algorithm function object)[edit]
      locates the partition point of a partitioned range
      (algorithm function object)[edit]
      Sorting operations
      checks whether a range is sorted into ascending order
      (algorithm function object)[edit]
      finds the largest sorted subrange
      (algorithm function object)[edit]
      sorts a range into ascending order
      (algorithm function object)[edit]
      sorts the first N elements of a range
      (algorithm function object)[edit]
      copies and partially sorts a range of elements
      (algorithm function object)[edit]
      sorts a range of elements while preserving order between equal elements
      (algorithm function object)[edit]
      partially sorts the given range making sure that it is partitioned by the given element
      (algorithm function object)[edit]
      Binary search operations (on sorted ranges)
      returns an iterator to the first elementnot less than the given value
      (algorithm function object)[edit]
      returns an iterator to the first elementgreater than a certain value
      (algorithm function object)[edit]
      determines if an element exists in a partially-ordered range
      (algorithm function object)[edit]
      returns range of elements matching a specific key
      (algorithm function object)[edit]
      Set operations (on sorted ranges)
      merges two sorted ranges
      (algorithm function object)[edit]
      merges two ordered ranges in-place
      (algorithm function object)[edit]
      returnstrue if one sequence is a subsequence of another
      (algorithm function object)[edit]
      computes the difference between two sets
      (algorithm function object)[edit]
      computes the intersection of two sets
      (algorithm function object)[edit]
      computes the symmetric difference between two sets
      (algorithm function object)[edit]
      computes the union of two sets
      (algorithm function object)[edit]
      Heap operations
      checks if the given range is a max heap
      (algorithm function object)[edit]
      finds the largest subrange that is a max heap
      (algorithm function object)[edit]
      creates a max heap out of a range of elements
      (algorithm function object)[edit]
      adds an element to a max heap
      (algorithm function object)[edit]
      removes the largest element from a max heap
      (algorithm function object)[edit]
      turns a max heap into a range of elements sorted in ascending order
      (algorithm function object)[edit]
      Minimum/maximum operations
      returns the greater of the given values
      (algorithm function object)[edit]
      returns the largest element in a range
      (algorithm function object)[edit]
      returns the smaller of the given values
      (algorithm function object)[edit]
      returns the smallest element in a range
      (algorithm function object)[edit]
      returns the smaller and larger of two elements
      (algorithm function object)[edit]
      returns the smallest and the largest elements in a range
      (algorithm function object)[edit]
      clamps a value between a pair of boundary values
      (algorithm function object)[edit]
      Permutation operations
      determines if a sequence is a permutation of another sequence
      (algorithm function object)[edit]
      generates the next greater lexicographic permutation of a range of elements
      (algorithm function object)[edit]
      generates the next smaller lexicographic permutation of a range of elements
      (algorithm function object)[edit]

      [edit]Constrained numeric operations

      Defined in header<numeric>
      Defined in namespacestd::ranges
      fills a range with successive increments of the starting value
      (algorithm function object)[edit]

      [edit]Constrained fold operations

      Defined in header<algorithm>
      Defined in namespacestd::ranges
      left-folds a range of elements
      (algorithm function object)[edit]
      left-folds a range of elements using the first element as an initial value
      (algorithm function object)[edit]
      right-folds a range of elements
      (algorithm function object)[edit]
      right-folds a range of elements using the last element as an initial value
      (algorithm function object)[edit]
      left-folds a range of elements, and returns apair (iterator, value)
      (algorithm function object)[edit]
      left-folds a range of elements using the first element as an initial value, and returns apair (iterator,optional)
      (algorithm function object)[edit]

      [edit]Constrained uninitialized memory algorithms

      Defined in header<memory>
      Defined in namespacestd::ranges
      copies a range of objects to an uninitialized area of memory
      (algorithm function object)[edit]
      copies a number of objects to an uninitialized area of memory
      (algorithm function object)[edit]
      copies an object to an uninitialized area of memory, defined by a range
      (algorithm function object)[edit]
      copies an object to an uninitialized area of memory, defined by a start and a count
      (algorithm function object)[edit]
      moves a range of objects to an uninitialized area of memory
      (algorithm function object)[edit]
      moves a number of objects to an uninitialized area of memory
      (algorithm function object)[edit]
      constructs objects bydefault-initialization in an uninitialized area of memory, defined by a range
      (algorithm function object)[edit]
      constructs objects bydefault-initialization in an uninitialized area of memory, defined by a start and count
      (algorithm function object)[edit]
      constructs objects byvalue-initialization in an uninitialized area of memory, defined by a range
      (algorithm function object)[edit]
      constructs objects byvalue-initialization in an uninitialized area of memory, defined by a start and a count
      (algorithm function object)[edit]
      destroys a range of objects
      (algorithm function object)[edit]
      destroys a number of objects in a range
      (algorithm function object)[edit]
      destroys an object at a given address
      (algorithm function object)[edit]
      creates an object at a given address
      (algorithm function object)[edit]

      [edit]Constrained random number algorithms

      Defined in header<random>
      Defined in namespacestd::ranges
      fills a range with random numbers from a uniform random bit generator
      (algorithm function object)[edit]

      [edit]Return types

      Defined in header<algorithm>
      Defined in namespacestd::ranges
      provides a way to store an iterator and a function object as a single unit
      (class template)[edit]
      provides a way to store two iterators as a single unit
      (class template)[edit]
      provides a way to store two iterators as a single unit
      (class template)[edit]
      provides a way to store three iterators as a single unit
      (class template)[edit]
      provides a way to store three iterators as a single unit
      (class template)[edit]
      provides a way to store two objects or references of the same type as a single unit
      (class template)[edit]
      provides a way to store an iterator and a boolean flag as a single unit
      (class template)[edit]
      provides a way to store an iterator and a value as a single unit
      (class template)[edit]
      provides a way to store an iterator and a value as a single unit
      (class template)[edit]

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_algorithm_default_value_type202403L(C++26)List-initialization for algorithms
      __cpp_lib_ranges201911L(C++20)Ranges library andconstrained algorithms
      __cpp_lib_ranges_contains202207L(C++23)std::ranges::contains
      __cpp_lib_ranges_find_last202207L(C++23)std::ranges::find_last
      __cpp_lib_ranges_fold202207L(C++23)std::rangesfold algorithms
      __cpp_lib_ranges_iota202202L(C++23)std::ranges::iota
      __cpp_lib_ranges_starts_ends_with202106L(C++23)std::ranges::starts_with,std::ranges::ends_with
      __cpp_lib_shift201806L(C++20)std::shift_left,std::shift_right
      202202L(C++23)std::ranges::shift_left,std::ranges::shift_right
      __cpp_lib_ranges_generate_random202403L(C++26)std::ranges::generate_random

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      P3136R1C++20niebloids were allowed to be specified as special entities
      other than function objects
      required to be specified as function objects
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/algorithm/ranges&oldid=178068"

      [8]ページ先頭

      ©2009-2025 Movatter.jp