On 9 April 2013 13:30, Walter Bright <[email protected]> wrote:

> On 4/8/2013 5:39 AM, Manu wrote:
>
>> But D makes no further guarantee. I don't see how const in D is any
>> different
>> than const in C++ in that sense? That's basically the concept of const,
>> it's not
>> a useful concept for optimisation, only immutable is.
>>
>
> In C++, it is legal to cast away const and mutate it. That is undefined
> behavior in D.
>
> A D compiler can assume, for example, that a const reference passed to a
> pure function will not mutate that reference, nor anything transitively
> referred to by that reference. No such assumption can be made like that in
> C++.
>

But that's meaningless though, because there's always the possibility that
something somewhere else may have a non-const reference to that thing.
Can you suggest a case where const could EVER be used in any sort of
optimisation?
I don't think const can possibly offer anything to the optimiser in any
language, only type safety... I'd love to be wrong.

Reply via email to