我在编程中经常使用向量,并且通常遍历一个现有值的向量,我使用std :: find,如下所示:
std::vector<int> foo;
std::vector<int>::iterator pos( std::find( foo.begin(), foo.end(), bar );
Run Code Online (Sandbox Code Playgroud)
这是一个真正的问题.所以我从std :: vector派生了一个模板来提供一个find方法:
template<class T>
class foovector : public std::vector<T>
{
public:
typename std::vector<T>::iterator find( const T& value )
{
return std::find( this->begin(), this->end(), value );
}
};
Run Code Online (Sandbox Code Playgroud)
所以现在我可以更自然地找到它:
foovector<int> foo;
foovector<int>::iterator pos( foo.find( bar ) );
Run Code Online (Sandbox Code Playgroud)
我的问题是,这似乎是向量的一个自然而明显的扩展,那么为什么它不是STL的一部分甚至是提升?我觉得我在这里错过了一些奥术知识.