Make safe_iterator inline friends

François Dumont frs.dumont@gmail.com
Wed Aug 22 21:08:00 GMT 2018


Now that _Safe_iterator has been revisited I would like to cleanup its 
operators to make them globals and inline friends as much as possible.

This patch transform operator-(const _Safe_iterator<>&, difference_type) 
and operator+(const _Safe_iterator<>&, difference_type) into global 
namespace operators.

Otherwise it just make all operators inline friend.

Only operator== and != remains outside _Safe_iterator because all my 
attempts to make them inline friends failed. I understand that an inline 
friend within a base class is not a very clean design.

Compiler error was:

/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:459: 
error: redefinition of 'bool __gnu_debug::operator==(const _Self&, const 
_OtherSelf&)'
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:452: 
note: 'bool __gnu_debug::operator==(const _Self&, const _Self&)' 
previously declared here
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:473: 
error: redefinition of 'bool __gnu_debug::operator!=(const _Self&, const 
_OtherSelf&)'
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:466: 
note: 'bool __gnu_debug::operator!=(const _Self&, const _Self&)' 
previously declared here

I don't know if it is a compiler issue but keeping those operators that 
should apply for any category of safe iterator at namespace level is ok. 
There are not much operators within __gnu_debug and users normally don't 
explicitely use this namespace.

I added even more checks in testsuite_containers.h especially using 
std::rel_ops to make sure we have no ambiguity.

Tested under Linux x86_64 debug mode.

Ok to commit ?

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: safe_iterator_oprators.patch
Type: text/x-patch
Size: 33285 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180822/5436df83/attachment.bin>


More information about the Gcc-patches mailing list