このテンプレート関数を作成して、shared_ptr のコレクションから項目を見つけて削除します
template<class T>
bool FindAndDelete(set<shared_ptr<T>>& collection, shared_ptr<T> item)
{
auto foundItem = find(collection.begin(), collection.end(), item);
if(foundItem != collection.end())
{
collection.erase(foundItem);
return true;
}
else
{
return false;
}
}
質問: すべてのコレクションをカバーするために、どのように一般化できますか? (ベクトル、リストなど...)
例えば
template<class K, class T>
bool FindAndDelete(K<shared_ptr<T>>& collection, shared_ptr<T> item);
注: 私は C# 出身なので、コードが少しずれている可能性があります :) 訂正してください