According to this page, I can achieve constant time insertion if I use
iterator std::set::insert ( iterator position, const value_type& x );
<
It is not totally clear if the position
should be pointing before or after the insertion point. Some implementations work with either.
On the other hand, if you want different behavior for different containers, why don't you just write two overloads for your function, one for containers with a push_back
function and one for std::set
.