I have an empty container with reserved memory. My function (algorithm) doesn’t take a container, only the iterator to begin of it. How to add elements to container in this function? I need allocate memory and call the constructor, but how to call the constructor in place referenced by iterator?
I have an empty container with reserved memory. My function (algorithm) doesn’t take a
Share
Normally by using something like an
std::inserter_iterator. This, however, doesn’t normally eliminate the requirement for a pointer or reference to the container — it just stores that reference inside the iterator itself.If you have a pre-set iterator type, this does no good. If you have something like a normal algorithm that just needs to take and use something that uses an iterator interface to insert into the collection, it works beautifully.