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

Ric Parkin ric.parkin at ntlworld.com
Tue Jan 25 05:51:13 EST 2005


From: David Nash <David.Nash at wallstreetsystems.com>
> OK, I was thinking more about passing by reference.
> 
> 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. 
 
> Although I would prefer to see "proper" documentation of
> what a function is supposed to do, than have to deduce it from
> the signature.

But const *is* documentation - barring perverse implementators, a const argument *won't* be logically modified, and a non-const *will*.

So if you assume that your collegues aren't perverse, it tells you the intent of the function, as so is as good as your original comments.

Ric


-----------------------------------------
Email provided by http://www.ntlhome.com/





More information about the Effective-cpp mailing list