why there is no find for vector in C++

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

what\'s the alternative?

Should I write by myself?

6条回答
  •  春和景丽
    2021-02-14 03:20

    Having a 'find' functionality in the container class violates 'SRP' (Single Responsibility Principle). A container's core functionality is to provide interfaces for storage, retrieval of elements in the container. 'Finding', 'Sorting', 'Iterating' etc are not core functionality of any container and hence not part of it's direct interface.

    However as 'Herb' states in Namespace Principle, 'find' is a part of the interface by being defined in the same namespace as 'vector' namely 'std'.

提交回复
热议问题