Monthly Archives: July 2013

C++: implementing const_iterator and non-const iterator without code duplication

C++ 11

C++ 11

Over the last couple of weeks I’ve been working on a custom data structure that provides iterators (both const and “regular” non-const) that adhere to the STL C++ ’11 standards. Having these iterators would make my life easier, as it allows me to use standard STL algorithms (like std::find) on my data structures. However, implementing this data structure and the appropriate iterators made my life miserable for a few hours. Especially the implementation the two iterators without duplicating code wasn’t as straight-forward as I hoped. Here’s how I did it – it might help you (and me, when I want to do this again in the future)
Continue reading