I know this question was asked a million of times. And most of answers just says that object should be CopyAssignable and CopyConstructible. But documentation clearly says this is the rule (until C++11)! But still it doesn't work. Why?
Yes, the requirements are less strict now. However, right below the part you're referencing, the linked documentation clearly states that:
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements. (since C++11)
References don't meet the requirements of Erasable, therefore they still can't work.
The rules apply until C++11. In C++11 is required that element type is a complete type and meets the requirements of Erasable in which case references are not.
However you can use std::reference_wrapper to wrap your references and store them in a vector.
std::vector<std::reference_wrapper<T>> vector_of_references;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With