What features of D are you using now which you thought you'd never goint to use?
monarch_dodra
monarchdodra at gmail.com
Tue Jun 25 23:30:20 PDT 2013
On Tuesday, 25 June 2013 at 22:39:07 UTC, Jonathan M Davis wrote:
> On Wednesday, June 26, 2013 00:11:29 Timon Gehr wrote:
>> On 06/25/2013 10:37 PM, Jonathan M Davis wrote:
>> > On Tuesday, June 25, 2013 21:42:17 Timon Gehr wrote:
>> >> Take will check the wrapped range's 'empty' repeatedly.
>> >> takeExactly does
>> >> not need to do that at all.
>> >
>> > It only does that with assertions. ...
>>
>> https://github.com/D-Programming-Language/phobos/blob/master/std/range.d#L26
>> 48
>
> Clearly, I missed that. Well, it is true that takeExactly
> avoids calling empty
> on the range that it's wrapping in its own empty function, but
> it's pretty
> rare that a wrapper range doesn't call the wrapped empty in its
> own empty
> function. So, I'd tend to view that as on optimization on
> takeExactly's part
> rather than a deficiency on take's part.
>
> Regardless, it's definitely more efficient to use takeExactly
> when you can. The
> _only_ benefit to take over takeExactly (assuming that the
> propagation issue is
> fixed) is that you don't have to guarantee that the range
> you're passing it has
> enough elements. If you know that it does, then takeExactly is
> better.
>
> - Jonathan M Davis
In regards to Take/TakeExactly, it might be best to implement
both as a common struct? eg:
private struct TakeImplementation(bool Exactly = false)
{...}
alias Take = TakeImplementation!false;
private alias TakeExactly = TakeImplementation!true;
//TakeExactly is obscure
I mean, at the end of the day, except for "pop", they are
basically the same functions... I think it would be better to
have a few static ifs in select locations, rather than
duplicating everything with subtle differences...
More information about the Digitalmars-d
mailing list