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?
opDothas been scheduled for deprecation. That’s why it isn’t documented. Don’t use it. Usealias thisinstead. You can use it to alias a particular type or function to a type so that it can act like that type. e.g.will make it so that a variable of type
Swill implicitly convert tointusingS‘svaluefield. You can also alias functions that way: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 castSto a anint, but not the reverse. Regarldess,alias thisis intended for implementing implicit conversions.If
alias thisisn’t quite what you want, another possibility isopDispatch. It allows you to transform what’s on the right-hand side of the dot into other stuff (e.g. turn all calls tofoointobar). But, between those two, you should be able to do pretty much anything you were thinking of doing withopDot(and a lot more besides).