
On 11/18/2011 03:27 PM, Jeffrey Lee Hellrung, Jr. wrote:
On Fri, Nov 18, 2011 at 12:02 PM, Thomas Heller <thom.heller@googlemail.com>wrote:
On 11/18/2011 01:27 PM, Jeffrey Lee Hellrung, Jr. wrote:
Thanks for the review, Thomas! I just have a couple comments.
On Fri, Nov 18, 2011 at 10:49 AM, Thomas Heller <thom.heller@googlemail.com>wrote: [...]
Local Blocks: I can't see the value in that one. The example in the documentation doesn't help either, as those things are easily detected by any modern compiler, with the appropriate warning levels (ok, not in the assert case, but for other boolean contexts at least gcc does).
I *believe* there has been an instance in my own code where I had to const_cast a range to coerce a range algorithm to use const_iterator's for efficiency reasons...or something like that. I don't remember the details of the situation, but I can imagine instances where const access to an object would be more efficient than mutable access, e.g., if mutable access via operator[] must return a proxy. It can be difficult to guarantee in general that the compiler would optimize a syntactically-mutable-**semantically-const access into the equivalent syntactically-const access.
I see. But why do you need local blocks to achieve that?
I don't. I could just const_cast use of the variable everywhere I want it const-qualified. Or define a reference-to-const to the same effect. ...or use a local block.
You just sounded like you were angling for a legitimate use case for local blocks, and I tried to supply a plausible (if rare) one.
Right, and I am still thinking that having things like: { auto const & const_ref_to_object = ... } is preferrable (For C++03, replace it with the proper call to BOOST_AUTO or repeat the type). And if you really want a new, independent scope, why not just create a new function to make your intention even clearer. Can't think of a unique name for that? Hey, there are namespaces. IMHO, C++ already provides all necessary tools to express what local block does.