"Pat" <> wrote in news:40ad7b43$:
> When inserting an number, say X, into a vector, if X already is in the
> vector, then do nothing ( because I do want a repeated X occurs in the
> vector). Otherwise, push X into the container.
>
> Any efficient way to do this? Because my vector container is very larger.
>
> Thanks. Pat
If the type of X has (or can have) a relational operator defined on it,
then you ou can use a std::set<> in parallel with the vector to check for
existence in the set before adding it to the vector. Otherwise, you will
have to do a linear search using std::find. Is it possible you don't need
the vector at all and that what you really want is a set?
Gregg
|