new std.variant (was Re: The Right Approach to Exceptions)
Jonathan M Davis
jmdavisProg at gmx.com
Wed Feb 22 17:57:37 PST 2012
On Thursday, February 23, 2012 02:36:31 Juan Manuel Cabo wrote:
> Yeah, but I don't care about the underlying array. I care
> about multiple places referencing the same Appender. If I
> from any place that references it, it appends to the same
> appender. The Appender "array" has identity. Ranges do not:
> int bla = [1,2,3];
> int ble = bla;
> ble ~= 4;
> assert(bla.length == 3);
> This is very easy to solve with appender.
> This is what happens in Java:
> ArrayList<Integer> bla = new ArrayList<Integer>();
> ArrayList<Integer> ble = bla;
> //prints 2
> //prints 2
> (yikes, aint that verbose!)
> The ArrayList has identity. It is a class, so that it
> many variables reference the _same_ object.
> (this can be accomplished with structs too though, but
> not with ranges).
The D equivalent would really be Array, not Appender. I'm not sure that it's a
great idea to use Appender as a container - particularly when there are types
specifically intended to be used as containers. Appender is geared specifically
towards array building (like StringBuilder in Java, except generalized for all
arrays). If it's a container that you're looking for, then I really think that
you should use a container.
- Jonathan M Davis
More information about the Digitalmars-d