why there is no find for vector in C++

后端 未结 6 909
傲寒
傲寒 2021-02-14 03:13

what\'s the alternative?

Should I write by myself?

6条回答
  •  终归单人心
    2021-02-14 03:38

    what's the alternative?

    The standard offers std::find, for sequential search over arbitrary sequences of like-elements (or something like that).

    This can be applied to all containers supporting iterators, but for internally sorted containers (like std::map) the search can be optimized. In that case, the container offers it's own find member function.

    why there is no find for vector in C++?

    There was no point in creating a std::vector::find as the implementation would be identical to std::find(vector.begin(), vector.end(), value_to_find);.

    Should I write by myself?

    No. Unless you have specific limitations or requirements, you should use the STL implementation whenever possible.

提交回复
热议问题