Namespaces
Variants
Actions

std::ranges::ends_with

From cppreference.com
< cpp‎ | algorithm‎ | ranges
 
 
Algorithm library
Constrained algorithms and algorithms on ranges (C++20)
Constrained algorithms, e.g. ranges::copy, ranges::sort, ...
Execution policies (C++17)
Non-modifying sequence operations
Batch operations
(C++17)
Search operations
(C++11)                (C++11)(C++11)

Modifying sequence operations
Copy operations
(C++11)
(C++11)
Swap operations
Transformation operations
Generation operations
Removing operations
Order-changing operations
(until C++17)(C++11)
(C++20)(C++20)
Sampling operations
(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 namespace std::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
Numeric operations
(C++23)            
Operations on uninitialized storage
Return types
 
Defined in header <algorithm>
Call signature
template< std::input_iterator I1, std::sentinel_for<I1> S1,

          std::input_iterator I2, std::sentinel_for<I2> S2,
          class Pred = ranges::equal_to,
          class Proj1 = std::identity, class Proj2 = std::identity >
requires (std::forward_iterator<I1> || std::sized_sentinel_for<S1, I1>) &&
         (std::forward_iterator<I2> || std::sized_sentinel_for<S2, I2>) &&
         std::indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
constexpr bool ends_with( I1 first1, S1 last1,
                          I2 first2, S2 last2, Pred pred = {},

                          Proj1 proj1 = {}, Proj2 proj2 = {} );
(1) (since C++23)
template< ranges::input_range R1, ranges::input_range R2,

          class Pred = ranges::equal_to,
          class Proj1 = std::identity, class Proj2 = std::identity >
requires (ranges::forward_range<R1> || ranges::sized_range<R1>) &&
         (ranges::forward_range<R2> || ranges::sized_range<R2>) &&
         std::indirectly_comparable<ranges::iterator_t<R1>,
                                    ranges::iterator_t<R2>,
                                    Pred, Proj1, Proj2>
constexpr bool ends_with( R1&& r1, R2&& r2, Pred pred = {},

                          Proj1 proj1 = {}, Proj2 proj2 = {} );
(2) (since C++23)

Checks whether the second range matches the suffix of the first range.

1) Let N1 be ranges::distance(first1, last1) and N2 be ranges::distance(first2, last2):
  • If N1 < N2 is true, returns false.
  • Otherwise, returns ranges::equal(std::move(first1) + (N1 - N2), last1,
                  std::move(first2), last2, pred, proj1, proj2)
    .
2) Let N1 be ranges::distance(r1) and N2 be ranges::distance(r2).
  • If N1 < N2 is true, returns false.
  • Otherwise, returns ranges::equal(views::drop(ranges::ref_view(r1),
                              N1 - static_cast<decltype(N1)>(N2)),
                  r2, pred, proj1, proj2)
    .

The function-like entities described on this page are algorithm function objects (informally known as niebloids), that is:

Contents