Should this work?

Manu turkeyman at gmail.com
Fri Jan 10 16:40:25 PST 2014


On 11 January 2014 01:20, John Colvin <john.loughran.colvin at gmail.com>wrote:

> On Friday, 10 January 2014 at 15:19:39 UTC, John Colvin wrote:
>
>> On Friday, 10 January 2014 at 15:05:18 UTC, monarch_dodra wrote:
>>
>>> On Friday, 10 January 2014 at 14:31:31 UTC, John Colvin wrote:
>>>
>>>> or if you want something short and simple, define a free function:
>>>> auto popFrontRet(R)(ref R range)
>>>>   if(isInputRange!R)
>>>> {
>>>>   range.popFront();
>>>>   assert(!range.empty);
>>>>   return range.front;
>>>> }
>>>>
>>>
>>> *Unless* I'm mistaken, he was asking for something that returns the
>>> *popped* element?
>>>
>>> Re-reading the question, it does kind of sound a bit ambiguous now.
>>>
>>
>> Woops, of course:
>>
>> auto popFrontRet(R)(ref R range)
>>     if(isInputRange!R)
>> {
>>     auto tmp = range.front;
>>     range.popFront();
>> }
>>
>>
>> That also invalidates my second point to do with emptiness.
>>
>
> ugh, today is not my day:
>
>  auto popFrontRet(R)(ref R range)
>>     if(isInputRange!R)
>> {
>>     auto tmp = range.front;
>>     range.popFront();
>>     return tmp;
>> }
>>
>
Yes, this is what I did. It should be added to phobos, but I figured
there's a reason it's not there...
My point was, I want this more often than I want either of those other
primitives. I'm surprised it doesn't exist, and suspected I was just being
blind again.

I also wrote popFrontRetN to capture more than one element from the start.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140111/d23b688b/attachment-0001.html>


More information about the Digitalmars-d mailing list