I recently read about the various smart pointer types and i think that especially unique_ptr will be extremely useful, and shared_ptr with weak_ptr as well to some extent. However i'm not sure how to create "generic" functions which can deal with either pointer type and if that would even be a good idea.
So imagine having a vector of objects encapsulated by a smart pointer an you would like to apply some action to all elements using a function, something like this:
void doSomething(vector<shared_ptr<SomeType>>& array) {
// iterate over all array elements and do something
}
Obviously you will need to replicate this function three times for shared/unique/weak_ptr, which is somewhat cumbersome. It would be easier to have a "generic"/"polymorphic" smart pointer type which fits all of them for function parameter usage:
void doSomething(vector<generic_ptr<SomeType>>& array) {
// iterate over all array elements and do something
// no matter if array is a vector<shared_ptr> or vector<unique_ptr>
}
So, does there exist such a smart pointer? If yes - which problems may arise from its usage? If no - why not?