This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Typedef for iterators denoting positions to insert/erase


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]