Request: Implement constant folding for .dup

Stewart Gordon smjg_1998 at yahoo.com
Tue Feb 20 12:54:29 PST 2007


Don Clugston Wrote:
<snip>
> Just create a new const with the same value as the first one -- all 
> compile-time consts have value semantics.
> 
> ie,
> char [] a = "xyz";
> char [] b = a.dup;
> 
> would be the same as
> char [] a = "xyz";
> char [] b = "xyz";

So it would behave as though the programmer typed this rather than

    char[] a = "xyz";
    char[] b = a;

?  There doesn't appear to be any difference.  As I try it (both with and without const), the two reference the same copy of the string data either way.

But it's probably not defined.  OTOH you could try defining .dup to force the new constant/variable to reference a new copy; however, there's an ambiguity or two in this definition.  If you're using .dup to define a struct or class member initialiser, should it copy only once, or should every instance of the struct or class contain a new copy?  And what about templates?

Stewart.



More information about the Digitalmars-d mailing list