C++ iterator and const_iterator problem for own container class

后端 未结 3 2087
猫巷女王i
猫巷女王i 2020-12-09 05:10

I\'m writing an own container class and have run into a problem I can\'t get my head around. Here\'s the bare-bone sample that shows the problem.

It consists of a con

3条回答
  •  春和景丽
    2020-12-09 05:40

    You should have a look to the Boost.Iterators library, especially the iterator_facade and iterator_adaptor sections. They contain a build-up of an iterator "from scratch".

    It will show you how to write iterators without too much duplication, because most of the times the code the const and non-const versions is about the same, apart from the const qualification itself. Using templates it's possible to write it once, then declare two different types, and that's what the library documentation illustrates.

提交回复
热议问题