The Standard Template Library documentation for list says:
void push_back ( const T& x );
Add element at the end Adds a new element at the end of the list, right after its current last element. The content of this new element is initialized to a copy of x.
These semantics differ greatly from the Java semantics, and confuse me. Is there a design principle in the STL that I'm missing? "Copy data all the time"? That scares me. If I add a reference to an object, why is the object copied? Why isn't just the object passed across?
There must be a language design decision here, but most of the commentary I've found on Stack Overflow and other sites focuses on the exception throwing issues associated with the fact that all this object copying can throw exceptions. If you don't copy, and just handle references all those exception problems go away. Very confused.
Please note: in this legacy code base I work with, boost is not an option.