C++: STL troubles with const class members
<p>It is an open ended question.
Effective C++. Item 3. <strong>Use const whenever possible.</strong> Really?</p>

<p>I would like to make anything which doesn't change during the objects lifetime const. But const comes with it own troubles. If a class has any const member, the compiler generated assignment operator is disabled. Without an assignment operator a class won't work with STL. If you want to provide your own assignment operator, <strong>const_cast</strong> is required. That means more hustle and more room for error. How often you use const class members?</p>

<p><strong>EDIT:</strong> As a rule, I strive for const correctness because I do a lot of multithreading. I rarely need to implemented copy control for my classes and never code delete (unless it is absolutely necessary). I feel that the current state of affairs with const contradicts my coding style. Const forces me to implement assignment operator even though I don't need one. Even without <strong>const_cast</strong> assignment is a hassle. You need to make sure that all const members compare equal and then manually copy all non-const member.</p>

<p><strong>Code.</strong> Hope it will clarify what I mean. The class you see below won't work with STL. You need to implement an assignment for it, even though you don't need one.</p>

<pre><code>class Multiply {
public:
    Multiply(double coef) : coef_(coef) {}
    double operator()(double x) const {
        return coef_*x;
    }
private:
    const double coef_;
};
</code></pre>
