How to avoid code duplication implementing const and non-const iterators?

前端 未结 6 1070
借酒劲吻你
借酒劲吻你 2020-11-29 18:30

I\'m implementing a custom container with an STL-like interface. I have to provide a regular iterator and a const iterator. Most of the code for the two versions of the it

6条回答
  •  温柔的废话
    2020-11-29 19:16

    In addition to the suggestion that you might templatize the constness and non-constness, you could also reduce the amount of work by taking a look at Boost.Iterator tutorial - which also mentions the same solution.

提交回复
热议问题