C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fwd: ranges::collect

From: Corentin Adam <corentin.adam27_at_[hidden]>
Date: Thu, 26 Sep 2024 23:07:05 +0200
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
<https://godbolt.org/z/KGvaGboG7>?

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_at_[hidden]> a
écrit :

>
>
> On Wed, Sep 11, 2024, 11:56 AM Corentin Adam via Std-Proposals <
> std-proposals_at_[hidden]> 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
>
>>

Received on 2024-09-26 21:07:18