Seeking help with opend std
Ali Çehreli
acehreli at yahoo.com
Mon Jan 13 21:29:38 UTC 2025
On 1/12/25 11:25 AM, Anton Pastukhov wrote:
> On Saturday, 11 January 2025 at 05:12:02 UTC, monkyyy wrote:
>> On Friday, 27 December 2024 at 21:15:40 UTC, monkyyy wrote:
>>>
>>
>> Still want help
>>
>> https://github.com/opendlang/d/blob/main/source/odc/algorthims.d
>>
>> will take criticism from the usual suspects
>
> Please make popFront and popBack actually return popped values thanks
Historically that did not work at a time when
- C++ was the ruler
- Strong exception guarantee mattered
- Move constructors were not available
T popFront() {
/* ... */ // 1) Mutate the range
return front; // 2) Copy the element
}
The problem is with copying that popped value. If the copying itself
throws, the range is already modified. Such topics have been covered
extensively in books like Exceptional C++ by Herb Sutter.
If strong exception guarantee is indeed needed, the correct API is to
provide front() and popFront() separately. But once you have front()
anyway, why conflate the two actions of popping and providing in
popFront() again? So the current D InputRange API works.
Ali
More information about the Digitalmars-d
mailing list