DIP53 and DIP49 (ver2) - New definitions for qualified constructors and postblits

Timon Gehr timon.gehr at gmx.ch
Wed Dec 18 12:11:31 PST 2013


On 12/18/2013 06:33 PM, Joseph Rushton Wakeling wrote:
> On 18/12/13 18:20, Timon Gehr wrote:
>> Well, 'const' attached to a method is simply the notation used for
>> attaching
>> 'const' to the implicit 'this' parameter.
>
> Sure, but if you see a method:
>
>     struct Foo
>     {
>         const int bar() { ... }
>     }
>
> ... the instinctive interpretation of that is "This is a method that
> returns a const int."  You soon learn your mistake, but once you have,
> the mental association between one form of const and the other makes
> sense, even if you don't appreciate the subtlety of the fact that it's
> referring to the implicit "this" parameter.
>
> I suggest attaching const, immutable, etc. to constructors is similarly
> helpful by analogy, even if it strictly speaking means using the same
> keyword for two different things.

Something that would be closer to what is happening here would be to 
make the 'const' annotation on a method denote purity.


More information about the Digitalmars-d mailing list