Typedef for iterators denoting positions to insert/erase

François Dumont frs.dumont@gmail.com
Fri Aug 29 21:01:00 GMT 2014


On 29/08/2014 16:16, Jonathan Wakely wrote:
> 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?
>
>
     I would say why not give it a try. Based on the few classes I 
checked there is also often a different implementation so not that much 
occasions to benefit from it.

François



More information about the Libstdc++ mailing list