Request: Implement constant folding for .dup

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Feb 20 13:08:01 PST 2007


Don Clugston wrote:
> Stewart Gordon wrote:
>> Don Clugston Wrote:
>>> Since COW is used so much in D, especially with strings, allowing 
>>> "abc".dup to be constant-folded would greatly increase the amount of 
>>> existing code which could be used at compile-time.
>>
>> What would the semantics be exactly?
> 
> 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";

I see no problem with allowing this in compile-time functions. However, 
I can't think of any situation in which this would actually be useful. 
Since compile-time functions aren't allowed to use non-const arrays, 
they aren't allowed to modify elements of any arrays they have access 
to, right? So why would they need .dup?



More information about the Digitalmars-d mailing list