On 11 January 2014 01:20, John Colvin <john.loughran.col...@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.