views:

612

answers:

2

How can I overload the STL implementation for methods like find, erase and insert to take varying parameters? I tried to look up the overloading of STL methods but couldn't find any help.

+8  A: 

You can't overload the methods of a class without editing the code of that class.

Write your own free functions that act as helpers; they would take the relevant container class as the first parameter.

You can inherit from a class and add methods that way, but the std container classes are not designed to be inherited from.

Daniel Earwicker
to explain: destructing a derived object via pointer to base with a nonvirtual dtor is strictly UB. And the std container classes have nonvirtual dtors because they don't want a vtable. The STL is designed for static polymorphism so the suggested solution is to [..]
[..] just make a class that conforms to the same concept as vector and pass instances of that to function templates. Whether this is practical is arguable.
That's not my suggestion! :)
Daniel Earwicker
+2  A: 

You are not allowed to add overloads in the std namespace. Only specialization of functions and algorithms for your own data types are allowed. If you do want a different find, erase, insert... implement a wrapper (out of the std namespace) and use it.

And I would not recommend it either... What kind of overloads do you want to provide?

David Rodríguez - dribeas
just having custom arguments each of different type
Elroy