I'm trying to code an associative container compatible with std::map. To do so, I have to create an insert method that accept a new item in the form of an std::pair with the first component of a const type. For example : std::pair<const int, int> p
.
The problem I have is that such an object can't be assigned to another. So in the inner code of my MapCompatibleContainer, I can't copy the new pair to the private variable (a std::vector).
How can I work around this?
Thanks
As you say, you cannot assign to a const object.
The standard containers solve this by allocating raw memory and construct the object in place. Copy construction still works.
Also, the associative containers store each element in a separate memory block, so that they don't have to be copied later.
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