why there is no find for vector in C++

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

what\'s the alternative?

Should I write by myself?

6条回答
  •  你的背包
    2021-02-14 03:17

    Who told you that? There's is "find" algorithm for vector in C++. Ironically Coincidentally, it is called std::find. Or maybe std::binary_search. Or something else, depending on the properties of the data stored in your vector.

    Containers get their own specific versions of generic algorithms (implemented as container methods) only when the effective implementation of the algorithm is somehow tied to the internal details of the container. std::list<>::sort would be one example.

    In all other cases, the algorithms are implemented by standalone functions.

提交回复
热议问题