T[new] misgivings

Rainer Deyke rainerd at eldwood.com
Thu Oct 15 23:36:33 PDT 2009


Andrei Alexandrescu wrote:
> Rainer Deyke wrote:
>> So, what's the syntax for user-defined value types that are passed by
>> reference going to be?  ref struct?  opPass?
> 
> No need for new syntax. T[new] is a struct that has a pointer inside.

Without new syntax, there's no way to distinguish between assignment and
argument passing.  Either 'T[new]' is a value type or 'T[new]' is a
reference type.  Or 'T[new]' is a messy hybrid, like arrays in D1.
There is no way to create a *clean* hybrid with the language facilities
in D2.

If 'T[new]' has reference semantics, then assignment rebinds the
reference.  This actually works out fairly well, except for the problem
that 'T[new]' has reference semantics.

Preferred syntax:
  assert(is(typeof([1, 2, 3]) == int[new]));
  int[new] a = [1, 2, 3]; // Rebinds.

Syntax for people who insist that array literals should be constant:
  assert(is(typeof(create_array(1, 2, 3)) == int[new]));
  int[new] a = create_array(1, 2, 3); // Rebinds.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list