c++ - Best practice for avoiding code duplication while implementing iterator and const_iterator classes -


what best practices avoid code duplication when implementing class pairs such iterator , const_iterator or similar?

  • does 1 implement iterator in terms of const_iterator using lots of const_casts?
  • does 1 employ sort of traits class , end defining both iterator , const_iterator different instantiations of common template?

this seems common enough problem have canonical solution have failed find articles dedicated that.

i don't have experience implementing iterators, although think similar other projects. refactor common code, etc.

looking @ gnu libstdc++'s implementation of std::vector::iterator

#include <bits/stl_iterator_base_funcs.h> // ... template ... class vector : ... {     typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;     typedef __gnu_cxx::__normal_iterator<const_pointer, vector> const_iterator; }; 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -