equivariant functions
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Oct 14 11:53:46 PDT 2008
Steven Schveighoffer wrote:
> What about returning a member? i.e.:
>
> inout(typeof(s.ptr)) getptr(inout const(char)[] s) { return s.ptr;}
Yah there is a recurring problem - we need to find a notation that works
nicely and expressively for member functions as well as free functions.
For free functions an easy-to-explain-and-understand way is to have
"inout" mark the incoming / outgoing TYPE entirely, not only its
qualifier. Then:
inout stripl(inout const(char)[] s);
means: accept any subtype of const(char)[] and call that type "inout" in
the return type. Then it's easy to access dependent stuff:
typeof(inout.ptr) at(inout const(char)[] s);
Notice that for one-parameter functions there's not even a need to
specify the inout in the argument list because it's unambiguous:
inout stripl(const(char)[] s);
typeof(inout.ptr) at(const(char)[] s);
When you get into member functions things aren't quite nice:
class A
{
private int a;
inout clone() inout; // ehm
typeof(&inout.a) getPtrToA() inout; // ehm
}
> is that what you had in mind?
>
> this syntax is going to be used often, since it's what you would use for an
> accessor. So it should be simple to understand if possible.
Yah I agree. At this point I don't have any solid solution for
notation... please continue rolling out ideas.
Andrei
More information about the Digitalmars-d
mailing list