June 26, 2013
On Wednesday, June 26, 2013 08:30:20 monarch_dodra wrote:
> 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...

In almost all cases, takeExactly _does_ forward to take. The only cases when it doesn't are when you call takeExactly on the result of takeExactly (so you get the same type you had before) and when you call takeExactly on a finite range without length, in which case, it _can't_ be Take, because it functions differently (in particular, with takeExactly, it doesn't bother to check whether the source range is running out of elements, because it assumes that it has enough, which take doesn't do). And it's not like much gets duplicated with the struct that takeExactly defines in that one case. It's a very small struct that does very little. I really don't think that you'd buy anything by trying to combine that struct with Take. If anything, I think that it would complicate things unnecessarily.

At this point, I think that take and takeExactly share as much implementation as makes sense, and that's already most of the implementation. So, I really don't think that there's a problem here that needs fixing (aside from propagating the two traits that aren't currently being propagated in takeExactly like they should be).

- Jonathan M Davis
1 2 3 4 5 6
Next ›   Last »