[Joke] C++ and D namings

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 20 04:15:24 UTC 2021


On 1/19/21 10:59 PM, Ola Fosheim Grostad wrote:
> On Wednesday, 20 January 2021 at 01:30:15 UTC, H. S. Teoh wrote:
>> I'm not the least surprised.  After all, this is C++, the same 
>> language that lets you write 'const' on something, and then in the 
>> same breath write 'const_cast<...>' to pretend that you never wrote 
>> it, all the while your caller still believes that you're honoring your 
>> word on the 'const'.
>>
>> Nothing new under the sun. ;-)
> 
> Modifying it after const cast is undefined behaviour according to 
> cppreference. How would you prevent it? You can do the same in D.

Only if the real item is actually const. This is literally the first 
example on cppreference:

     int i = 3;                 // i is not declared const
     const int& rci = i;
     const_cast<int&>(rci) = 4; // OK: modifies i

-Steve


More information about the Digitalmars-d mailing list