I've met several mentions about opDot method, that allows to overload member access aka dot operator, but official documentation for it is missing. It's surely not dropped out, as std.typecons.Unique makes use of it.

Does anybody know, how opDot can be used, and why there is no documentation about it?

1 Answer
1

opDot has been scheduled for deprecation. That's why it isn't documented. Don't use it. Use alias this instead. You can use it to alias a particular type or function to a type so that it can act like that type. e.g.

struct S
{
int value;
alias value this;
}

will make it so that a variable of type S will implicitly convert to int using S's value field. You can also alias functions that way:

struct S
{
int get()
{
return 7;
}
alias get this;
}

though that can be more limiting, since dmd does not currently support having multiple alias thises for a type (it should eventually though). In this case, you can then implicitly cast S to a an int, but not the reverse. Regarldess, alias this is intended for implementing implicit conversions.

If alias this isn't quite what you want, another possibility is opDispatch. It allows you to transform what's on the right-hand side of the dot into other stuff (e.g. turn all calls to foo into bar). But, between those two, you should be able to do pretty much anything you were thinking of doing with opDot (and a lot more besides).