c++stlreference-manual

Write C++ container that fits neatly into STL


I would like to write a container class in a style which fits very neatly into STL. It should look and behave as if it where a standard STL container.

Is there a manual, report, Q&A, etc., out there that describes how to write code with these set of features? Such a text should compromise design principles of the STL, pitfalls, coding conventions, and the like.

PS: This question has been partly inspired by that one: C++ vector with dynamic item size although that idea is not about template classes.


Solution

  • It is not very difficult (for simple data stuctures). You should read the chapter about containers in the C++ standard. You can download the draft of the upcoming C++1x standard here :

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/#mailing2011-04

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf

    You might want to use boost::iterateror_facade when writing the iterators.

    http://www.boost.org/doc/libs/1_46_1/libs/iterator/doc/iterator_facade.html