new std.variant (was Re: The Right Approach to Exceptions)

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 22 12:57:57 PST 2012


On Wednesday, February 22, 2012 14:24:49 Robert Jacques wrote:
> I view appender's purpose as array building, which is slightly different
>  from simply speeding up array appending. Simply put, an array is a
> terrible data structure for building arrays. But, I can appreciate the
> need for mutation and if a particular array building algorithm can't be
> performed on appender, then appender has failed. Would exposing a
> bidirectional array be sufficient for your usages? A random access range?

Well, as long as you don't have access to the actual array, you're going to 
lose something. There are functions that you just won't be able to use because 
they take an array. However, a range with essentially the same properties as a 
range (bidirectional, random access, etc.) would cover a large number of the 
functions that you might want to call. And if you need to hide the array for 
speed for efficiency for some reason - especially if it results in a large 
increase in speed - then that could at least partially outweigh the cost of 
losing the array (especially if Appender has an API to at least use it as a 
range). But I'd definitely be against hiding it simply for safety, since speed 
is really its whole point of existance. I don't know why else you'd ever use 
appender.

So, I don't really like the idea of losing access to the underlying array, but 
if you can provide at least make it so that you could use it with range-based 
functions, and the changes provides a sigificant speed improvement, then the 
need for speed arguably outweighs the loss of being able to use the internal 
array directly.

- Jonathan M Davis


More information about the Digitalmars-d mailing list