Write C++ container that fits neatly into STL

后端 未结 4 1109
-上瘾入骨i
-上瘾入骨i 2020-12-28 16:58

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 man

相关标签:
4条回答
  • 2020-12-28 17:15

    I recommend reading Herb Sutter's "Unstrung". It's an in-depth look at std::string, covering what went right and what could've been done better. I highly value his opinion on C++ programming matters. It's a long read, but I guarantee you'll learn a few useful things about writing classes in the style of the C++ standard library (and about writing classes in general).

    You could also take a look at Scott Meyers' Effective STL. That book will give you a good overview of the expectations levied on the users of standard library containers. Having that insight will help you write better container classes yourself.

    0 讨论(0)
  • 2020-12-28 17:30

    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

    0 讨论(0)
  • 2020-12-28 17:33

    I'd recommending reading Josuttis, The C++ Standard Library: A Tutorial and Reference. It gives clear and easy to read explanations of the principles behind STL.

    0 讨论(0)
  • 2020-12-28 17:41

    Besides the one recommended by user763305, I would also look at Austern, Generic Programmming and the STL: Using and Extending the C++ Standard Template Library. It discusses these sorts of issues and serves as a good reference for the concepts in STL.

    0 讨论(0)
提交回复
热议问题