I hadn't thought of it that way, but I agree with you that it would work too.
If I understand correctly, you mean some range constructors like this

I've searched through the current proposals and it seems to me that these constructors haven't been proposed yet (even in the optional range support proposal), have they?
If they haven't yet been proposed, what do you think about drafting a proposal to include them?

Another question, why favor the constructor from ranges approach over the collect free function approach?

Thank you.

Corentin Adam

Le mer. 11 sept. 2024 à 19:47, Barry Revzin <barry.revzin@gmail.com> a écrit :


On Wed, Sep 11, 2024, 11:56 AM Corentin Adam via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
Hi everyone,

I've recently been working on a cpp implementation of the rust collect function: : https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect.

This function has two main uses in rust: 
 * construct containers from ranges (exactly the work achieved by std::ranges::to)  
 * collect ranges of expected/optional values into expected/optional range of value. Thus, if all values in the range are correct (in other words has_value() == true), the return value is true and contains the range of underlying values. Otherwise, the return value contains the first error encountered in the range.

ranges::to can support the second use-case as well. We just need to add the appropriate constructor to optional and expected.

Barry