- Generalized array of containers, parameterized object contains the type
- Function generalization of algorithm, parameterized with the iterator type
- Pointer generalizations iterators, parameterized type of object points
Second, similar container has a similar function
- Contiguous-memory containers provide random access iterators
- Provides bidirectional iterator node-based containers
- Container supports sequence
push_front
orpush_back
, but does not support the associated container - Complexity associated with the container to provide a number of times
lower_bound
,upper_bound
andequal_range
member functions, but the container has not sequence
Third, the use package --typdedf
Do not write code like
class Widget {...}; vector<Widget> vw; Widget bestWidget; ... // 给bestWidget一个值 vector<Widget>::iterator i = bestWidget相等的Widget find(vw.begin(), vw.end(), bestWidget);
Using typedef define a container type, such that the change easier
class Widget { ... }; typedef vector<Widget> WidgetContainer; typedef WidgetContainer::iterator WCIterator; WidgetContainer cw; Widget bestWidget; ... WCIterator i = find(cw.begin(), cw.end(), bestWidget);
Third, the container type hidden in the class
Do not use direct container, to create a class, the use of standard containers on the private area
class CustomerList { private: typedef list<Customer> CustomerContainer; typedef CustomerContainer::iterator CCIterator; CustomerContainer customers; public: // 通过这个接口 ... // 限制list特殊信息的可见性 };
Original: Big Box clause 2 Carefully container-independent code fantasy