Making types immutable is often desireable, especially for multi-threaded applications. There's no need to worry about concurrent access and no need for any synchronization. The common STL containers require the contained objects to be assignable, however, so they don't work with immutable types.
How should I strike a balance between wanting immutable types and wanting STL-compatible types? What I could:
- provide an assignment operator and stop worrying about immutability. Either add synchronization or document that object assignment isn't thread-safe.
- live with the fact that the types can't go directly into containers and wrap them in
What are the tradeoffs involved and which solution should I prefer for what types of objects? Should I strive to always make my objects STL compatible or should I only do that when I anticipate need for it? Should I strive to always make my objects immutable or only when I see concrete benefit from it?