what is the preferred way to expose custom STL-style iteration?

前端 未结 4 1912
春和景丽
春和景丽 2020-12-19 04:47

(also see Is there a good way not to hand-write all twelve required Container functions for a custom type in C++? )


For a class such as

namespa         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-19 05:18

    There is a standard which describes what your class interfaces should look like if you want them to be congruent with the STL. C++ has this notion of 'concepts' which pin down the requirements for a given class to be a sufficient implementation of a concept. This almost became a language feature in c++11.

    A concept you may be interested in is the Container concept. As you can see, in order to meet the requirements of the Container concept, you need begin, cbegin, end, and cend as member functions (among other things).

    Since it looks like you're storing your data in an array, you might also be interested in SequenceContainer.

提交回复
热议问题