resizeable arrays: T[new]

Brad Roberts braddr at puremagic.com
Tue Jun 5 11:30:12 PDT 2007


I believe that code would not need to change to retain existing behavior.

The function args aren't const by default since it's not using 'in'.  So 
it'll be fine.  The syntax used is also to pass a slice. which would 
become non-resizeable, which you're not resizing, so that's fine.  Slices 
are to retain their write through behavior, so that's fine.  Your 
initialization of buf would have an implicit cast from dup's T[new] to 
buf's T[], which works.  Passing a T[] to a function taking a T[] is 
perfectly normal.. 

So, that code 'just works'.

Later,
Brad

(now, time for Walter to point out the flaw in my reasoning)

On Tue, 5 Jun 2007, Sean Kelly wrote:

> Date: Tue, 05 Jun 2007 10:16:53 -0700
> From: Sean Kelly <sean at f4.ca>
> Reply-To: digitalmars.D.announce <digitalmars-d-announce at puremagic.com>
> To: digitalmars-d-announce at puremagic.com
> Newsgroups: digitalmars.D.announce
> Subject: Re: resizeable arrays: T[new]
> 
> It just occurred to me this morning that I may have missed something regarding
> the proposed const changes.  Given the following D 1.0 code, can someone tell
> me whether or how it will change in D 2.0?
> 
>     void alter( char[] str )
>     {
>         str[0] = 'x';
>     }
> 
>     char[] buf = "abc".dup;
> 
>     alter( buf );
>     alter( buf[1 .. $] );
> 
>     printf( "%.*s\n", buf ); // should print "xxc"
> 
> 
> 
> Sean
> 



More information about the Digitalmars-d-announce mailing list