Regarding std.array.Appender

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 29 18:43:14 PST 2012


On Thursday, March 01, 2012 03:29:06 Adam D. Ruppe wrote:
> On Thursday, 1 March 2012 at 02:23:55 UTC, bearophile wrote:
> > But for me it's weird that Appender doesn't use the D operator
> > to _append_.  [...] I suggest to give it both "put" method and
> > "~=" operator.
> 
> I agree entirely.
> 
> 
> Another annoyance is if you have a function that works on
> regular arrays, you probably used ~=.
> 
> But you decide to switch to Appender to try for a speed boost.
> 
> Now you have to change all the usage too, since the interfaces
> are incompatible!

True, but it can't do all of the other operations that array can do either. 
It's an output range, not an array. And odds are that it's going to be 
refactored such that it doesn't even contain an array internally anymore, 
beacause that's an inefficient way to implement appending. Someone (Robert 
Jacques IIRC, but I'd have to check) has already created such an 
implementation, and there's a decent chance that it's going to make it into 
Phobos.

So, I'm not sure that treating Appender as an array is really a good idea in 
the first place. If you want the truly generic approach, then treat is an 
output range.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list