const challenge

Steven Schveighoffer schveiguy at yahoo.com
Sun Feb 3 07:06:32 PST 2008


"Janice Caron" wrote
> On 2/1/08, Sergey Gromov wrote:
>> On second thoughts, why would you want a function with a unique
>> parameter ?  Nothing casts to unique(), so that the caller is always
>> required to dup() or whatever.
>
> So that you can do
>
>    string s;
>    string t = f( g( h( i( j( k( s ))))));
>
> The functions f,g,h,i,j and k all return unique. The functions f,g,h,i
> and j (but not k) all accept a unique parameter. In this example, no
> duping or casting is required, because the temporary value is unique
> right the way through the chain.
>

Can't you just declare the functions as accepting mutable strings?  Doesn't 
unique(char)[] implicitly cast to char[]?  As Sergey says, this FORCES you 
to do a dup if you don't have a unique value.

-Steve 





More information about the Digitalmars-d mailing list