<div dir="ltr">On 9 April 2013 13:30, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 4/8/2013 5:39 AM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But D makes no further guarantee. I don't see how const in D is any different<br>
than const in C++ in that sense? That's basically the concept of const, it's not<br>
a useful concept for optimisation, only immutable is.<br>
</blockquote>
<br></div>
In C++, it is legal to cast away const and mutate it. That is undefined behavior in D.<br>
<br>
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++.<br>

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