Pass by reference

Deewiant deewiant.doesnotlike.spam at gmail.com
Fri Jun 8 10:38:42 PDT 2007


Deewiant wrote:
> Regan Heath wrote:
>> Hmm.. idea;  why not allow foo(a) and automatically convert to foo(&a)
>> internally if 'a' is not a pointer.  I mean, the compiler knows what 'a' is,
>> it knows what 'foo' wants, why can't we have the syntax automatically, much
>> like we do for dereferencing.
>>
> 
> We'd lose the ability to overload a function with both foo(A) and foo(A*), but
> to be honest I can't think of a use case for that anyway. I like it! We could
> lose 'ref' completely.
> 

Didn't take long to come up with a case:

bool contains(char[] string, char character);
bool contains(char[] string, char* cstring);
bool contains(char[] string, char[] string2);

With first-class arrays I'd say this isn't a big problem, and I'd say the
handiness of your idea is worth the minor hassle of having to pass cstring to a
toString function, but it's something to consider.

-- 
Remove ".doesnotlike.spam" from the mail address.



More information about the Digitalmars-d mailing list