equivariant functions

Steven Schveighoffer schveiguy at yahoo.com
Tue Oct 14 10:08:18 PDT 2008


"Andrei Alexandrescu" wrote
> Steven Schveighoffer wrote:
>> One other syntax that Janice proposed (and I later put into a bugzilla), 
>> is to use the dead keyword inout.  Meaning, what you send in is what you 
>> get out.  ref already completely replaces inout, so there is no need to 
>> keep it under its current meaning:
>>
>> inout(char)[] stripl(inout(char)[] s);
>>
>> I'm not in love with this completely, but it has the benefit of not 
>> requiring a new keyword.
>
> Also I guess:
>
> class C
> {
>     Range!(inout(C)) foo() inout;
> }
>
> And also:
>
> class Base {}
> class Derived : Base {}
> inout foo(inout Base b);
>
> I think this could work and doesn't look half bad. Of course, you'll be 
> tasked with addressing protests about yet another D1/D2 incompatibility. 
> :o)

One thing that should be mentioned, my original post implied that the 'base 
type' is implied to be const (since originally, this is the only problem I 
was trying to solve).

So in my example:

inout(char)[] stripl(inout(char)[] s);

s is implied to be const(char) during the function.  With your 
interpretation of inout meaning 'anything that is derived from', then I 
suppose the correct syntax should be:

inout(const(char))[] stripl(inout(const(char))[] s);

With your special trick of implying the return type looking like this:

inout[] stripl(inout(const(char))[] s);

Not as appealing, but it still works.

-Steve 





More information about the Digitalmars-d mailing list