using this instead of typeof(this)

monarch_dodra monarchdodra at gmail.com
Tue Feb 26 10:27:33 PST 2013


On Tuesday, 26 February 2013 at 18:22:03 UTC, Kenji Hara wrote:
> Returning S, S!(...), and typeof(this) are identical...
> Kenji Hara

Just note that if the function is const or immutable, then 
"typeof(this)" will be "immutable S!(...)", where as if you use 
an actual "S!(...)" as your return value, you'll get a mutable 
return.

This can make a difference depending on if or if not you can 
strip constness by copy, for functions such as:

R!T save() const;
vs
typeof(this) save() const;

Just wanted to note it. It's a subtle difference that's often 
forgotten.


More information about the Digitalmars-d-learn mailing list