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

Robert Jacques sandford at jhu.edu
Wed Feb 22 18:07:37 PST 2012


On Wed, 22 Feb 2012 19:57:37 -0600, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> 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>();
>> bla.add(1);
>> ArrayList<Integer> ble = bla;
>> ble.add(2);
>> //prints 2
>> System.out.println(Integer.toString(bla.size()));
>> //prints 2
>> System.out.println(Integer.toString(ble.size()));
>>
>> (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

StringBuilder in .Net is implemented using lists and doesn't expose iteration nor indexing; why are we worrying about the indexing and container performance of D's appender?


More information about the Digitalmars-d mailing list