Seeking help with opend std

Anton Pastukhov mail at anton9.com
Tue Jan 14 11:19:50 UTC 2025


On Monday, 13 January 2025 at 21:29:38 UTC, Ali Çehreli wrote:
> 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

This is just a matter of ergonomics.
```d
auto x = myArr.popFront();
```

is slightly more convenient than
```d
myArr.popFront()
auto x = myArr.front;
```

Re: exceptions, for builtin range data types it's realistic to 
give nothrow guarantee. For user-defined types, it's 
responsibility of the user to take care of it


More information about the Digitalmars-d mailing list