Does const-correctness give the compiler more room for optimization?

[Edit: OK so this question is more subtle than I thought at first.] Declaring a pointer-to-const or reference-of-const never helps any compiler to optimize anything. (Although see the Update at the bottom of this answer.) The const declaration only indicates how an identifier will be used within the scope of its declaration; it does not … Read more

“const correctness” in C#

I’ve come across this issue a lot of times too and ended up using interfaces. I think it’s important to drop the idea that C# is any form, or even an evolution of C++. They’re two different languages that share almost the same syntax. I usually express ‘const correctness’ in C# by defining a read-only … Read more

Sell me on const correctness

This is the definitive article on “const correctness”: https://isocpp.org/wiki/faq/const-correctness. In a nutshell, using const is good practice because… It protects you from accidentally changing variables that aren’t intended be changed, It protects you from making accidental variable assignments, and The compiler can optimize it. For instance, you are protected from if( x = y ) … Read more

What is the reason behind cbegin/cend?

It’s quite simple. Say I have a vector: std::vector<int> vec; I fill it with some data. Then I want to get some iterators to it. Maybe pass them around. Maybe to std::for_each: std::for_each(vec.begin(), vec.end(), SomeFunctor()); In C++03, SomeFunctor was free to be able to modify the parameter it gets. Sure, SomeFunctor could take its parameter … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)