Proposal: takeFront and takeBack

deadalnix deadalnix at gmail.com
Wed Jul 4 03:44:51 PDT 2012


Le 03/07/2012 19:27, monarch_dodra a écrit :
> On Tuesday, 3 July 2012 at 17:22:17 UTC, Wouter Verhelst wrote:
>> Jonathan M Davis <jmdavisProg at gmx.com> writes:
>>
>> Couldn't you just overload popFront?
>>
>> have a void popFront which throws off the first element without
>> returning anything, and an auto popFront which does return data.
>>
>> I'd always been taught that "pop" means "read a bit and chop it off",
>> which means that having to first read the front and then pop it off
>> (i.e., in two separate methods) feels rather counterintuitive to
>> me. That's in addition to the fact that yes, there's a performance
>> issue.
>>
>> But hey, I've only been doing this D thing for a few weeks, so feel free
>> to ignore me if I'm not making any sense :-)
>
> You can't overload by return value, so that is not possible.
>
> As far as I can recall, I've always been taught that pop does NOT
> (should not) return a value. Rationale being it makes you pay for a
> read/copy you may not have asked for. That's the way C++ does it, and is
> what I've come to expect from any language.

Many languages does this (it doesn't mean it is the right thing to do). 
Do you know why this shouldn't be done ?


More information about the Digitalmars-d mailing list