This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Immediate status.

4465. §[alg.partitions] Clarify Returns: element

Section: 26.8.5 [alg.partitions] Status: Immediate Submitter: Ruslan Arutyunyan Opened: 2025-11-07 Last modified: 2025-11-08

Priority: Not Prioritized

View all other issues in [alg.partitions].

View all issues with Immediate status.

Discussion:

Addresses US 162-261

In 26.8.5 [alg.partitions] p21 the wording is unclear what happens if there is no such element. The proposed resolution tries to clarify that without complicating the wording. If the proposed resolution (or something along those lines) fails, the recommendation is to reject US 162-261.

[Kona 2025-11-07; approved by LWG. Status changed: New → Immediate.]

Proposed resolution:

This wording is relative to N5014.

  1. Modify 26.8.5 [alg.partitions], as indicated:

    template<class InputIterator, class OutputIterator1, class OutputIterator2, class Predicate>
      constexpr pair<OutputIterator1, OutputIterator2>
        partition_copy(InputIterator first, InputIterator last,
                       OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
    […]
    template<execution-policy Ep, sized-random-access-range R,
             sized-random-access-range OutR1, sized-random-access-range OutR2,
             class Proj = identity,
             indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
      requires indirectly_copyable<iterator_t<R>, iterator_t<OutR1>> &&
                indirectly_copyable<iterator_t<R>, iterator_t<OutR2>>
      ranges::partition_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR1>,
                                    borrowed_iterator_t<OutR2>>
        ranges::partition_copy(Ep&& exec, R&& r, OutR1&& out_true_r, OutR2&& out_false_r,
                               Pred pred, Proj proj = {});
    

    -14- Let proj be identity{} for the overloads with no parameter named proj and let E(x) be bool(invoke(pred, invoke(proj, x))).

    […]

    -19- Preconditions: The input range and output ranges do not overlap. […]

    -20- Effects: For each iterator i in [first, first + N), copies *i to the output range [out_true, last_true) if E(*i) is true, or to the output range [out_false, last_false) otherwise.

    -21- Returns: Let o1 Q be the iterator past the last number of elements copied element into the output range [out_true, last_true), and o2 V be the iterator past the last number of elements copied element into the output range [out_false, last_false). Returns:

    • (21.1) — {o1out_true + Q, o2out_false + V} for the overloads in namespace std.
    • (21.2) — {first + N, o1out_true + Q, o2out_false + V} for the overloads in namespace ranges.

    -22- Complexity: At most last - first applications of pred and proj.