[Exceptional C++ Style] Exceptional C++ Style - Item 24:Cons tantOptimization

Adrian Fagg adrianf at evaluategroup.com
Tue Jan 25 06:32:37 EST 2005


> -----Original Message-----
> From: effective-cpp-bounces at accu.org
> [mailto:effective-cpp-bounces at accu.org]On Behalf Of Ric Parkin
> Sent: 25 January 2005 10:51

> > void foo (int& param); //param *might* get modified
> > void foo (const int& param); //param won't get modified
>
> Your comments aren't accurate ;-)
>
> // param may or may not be modified
> void foo (int& param);
>
> // param may or may not be modified
> void foo (const int& param);
>
> const_cast and mutable cause *such* fun.

Your comment isn't accurate.;-);-)
an int doesn't contain any mutable members, so doesn't apply in this case.
More to the point, I don't think mutable is as previously mentioned 'morally
equivalent to const_cast'. const_cast really only exists to allow you to use
code that was never const correct in the first place. mutable is there for
the support of operations that are logically const *as seen from the
outside*, which moves it out of this discussion IMO.

Of course, mutable could be abused, but why bother?

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/




More information about the Effective-cpp mailing list