default values for inout parameters

Charlie charlies at nowhere.com
Tue Dec 5 16:27:12 PST 2006


BCS wrote:
> Charlie wrote:
>> Yea I was trying to abuse it, you're right it shouldn't work with 
>> default parameters, what I was really trying to do was something like
>>
>> char [] x = char[]
>>
>> Charlie
>>
> 
> Are you looking for some sort of "stuff in a throw away value" feature?
> 
> void foo(int i, inout char[] foo = /** somthing **/ )
> {
>     foo = "hello";
> }
> 
> char[] a;
> foo(1, a);
> assert(a == "hello");
> foo(1); // no side effects
> 
> What would be nice would be something like "Non l-values used for inout 
> parameters get passed as copies and discarded after use."
> 

Yes thats what I was looking for :).

Charlie



More information about the Digitalmars-d-learn mailing list