On 8/1/2011 4:36 PM, Jonathan M Davis wrote:
You lose logical const, which he has wanted to use in stuff that he's been
doing (games I think). He wants to lazy load values in his objects. You can't
do that with D's const. It pretty much means that that you have to either
eager load it or give up on const. It's totally doable, but it forces you to
change your design in a manner which you might not like.

I've talked to many people who use logical const extensively in C++, and really want it. If you dig down into what's happening, you'll find that logical const isn't actually supported by C++. It's a convention. There's simply nothing in the language that enforces that convention.

The reason "logical const" does not work with const in D is because D actually enforces const semantics, and relies on that enforcement.

Since logical const is a convention in C++ anyway, you can have logical const in D, too. Just put in a comment:

   struct S /* This struct is logical const */
   { ... }

and then follow the convention just as you would with C++.

Const in C++ is not powerful - it's simply a fraud - and the two get confused.

Reply via email to