Typedef for iterators denoting positions to insert/erase

Jonathan Wakely jwakely@redhat.com
Fri Aug 29 14:16:00 GMT 2014


In the new std::string implementation I'm using the following typedef:

#if __cplusplus < 201103L
      typedef iterator __pos_iterator;
#else
      typedef const_iterator __pos_iterator;
#endif

This can then be used to avoid littering the rest of the file with preprocessor
conditionals like:

      iterator
#if __cplusplus >= 201103L
      erase(const_iterator __first, const_iterator __last) noexcept
#else
      erase(iterator __first, iterator __last)
#endif
      {
      ...
      }

Is this worth doing in the other containers too?

I'm undecided whether it's clearer to read the preprocessor condition
or a declaration with the non-standard __pos_iterator type, but I
think I'd prefer to use the new type. Any other opinions?



More information about the Libstdc++ mailing list