Make associative container operators inline friend

François Dumont frs.dumont@gmail.com
Thu Sep 27 20:38:00 GMT 2018


Hi

     Here is a patch to make all associative containers operators inline 
friends. This is for both container operators themselves and their 
associated iterators.

     Note that I also remove iterator/const_iterator == and != 
operators. They are useless as iterator can be implicitly converted into 
const_iterator so as soon as there is a mix the conversion will take 
place (and is cheap). Do you see an ABI issue ?

     I also wonder if Doxygen will properly manage doc on operators I 
kept when moving those inline.

     Before I came to this result I faced some problems which make me 
introduce the _Rb_tree cbegin and cend and use it to avoid sometimes 
iterator/const_iterator comparisons or conversions. Even if eventually 
useless I propose to keep it.

     I also benefit from C++11 syntax simplifications in _GLIBCXX_DEBUG 
associatives containers implementations.

     * include/bits/stl_tree.h
     (_Rb_tree_iterator<>::operator==): Make inline friend.
     (_Rb_tree_iterator<>::operator!=): Make inline friend.
     (_Rb_tree_const_iterator<>::operator==): Make inline friend.
     (_Rb_tree_const_iterator<>::operator!=): Make inline friend.
     (operator==(const _Rb_tree_iterator<>&,
     const _Rb_tree_const_iterator&)): Remove.
     (operator!=(const _Rb_tree_iterator<>&,
     const _Rb_tree_const_iterator&)): Remove.
     (_Rb_tree<>::cbegin()): New.
     (_Rb_tree<>::cend()): New.
     (operator==(const _Rb_tree<>&, const _Rb_tree<>&)): Make inline friend.
     (operator!=(const _Rb_tree<>&, const _Rb_tree<>&)): Likewise.
     (operator<(const _Rb_tree<>&, const _Rb_tree<>&)): Likewise.
     (operator>(const _Rb_tree<>&, const _Rb_tree<>&)): Likewise.
     (operator<=(const _Rb_tree<>&, const _Rb_tree<>&)): Likewise.
     (operator>=(const _Rb_tree<>&, const _Rb_tree<>&)): Likewise.
     * include/bits/stl_map.h
     (operator==(const map<>&, const map<>&)): Make inline friend.
     (operator!=(const map<>&, const map<>&)): Likewise.
     (operator<(const map<>&, const map<>&)): Likewise.
     (operator>(const map<>&, const map<>&)): Likewise.
     (operator<=(const map<>&, const map<>&)): Likewise.
     (operator>=(const map<>&, const map<>&)): Likewise.
     * include/bits/stl_multimap.h
     (operator==(const multimap<>&, const multimap<>&)): Make inline friend.
     (operator!=(const multimap<>&, const multimap<>&)): Likewise.
     (operator<(const multimap<>&, const multimap<>&)): Likewise.
     (operator>(const multimap<>&, const multimap<>&)): Likewise.
     (operator<=(const multimap<>&, const multimap<>&)): Likewise.
     (operator>=(const multimap<>&, const multimap<>&)): Likewise.
     * include/bits/stl_set.h
     (operator==(const set<>&, const set<>&)): Make inline friend.
     (operator!=(const set<>&, const set<>&)): Likewise.
     (operator<(const set<>&, const set<>&)): Likewise.
     (operator>(const set<>&, const set<>&)): Likewise.
     (operator<=(const set<>&, const set<>&)): Likewise.
     (operator>=(const set<>&, const set<>&)): Likewise.
     * include/bits/stl_multiset.h
     (operator==(const multiset<>&, const multiset<>&)): Make inline friend.
     (operator!=(const multiset<>&, const multiset<>&)): Likewise.
     (operator<(const multiset<>&, const multiset<>&)): Likewise.
     (operator>(const multiset<>&, const multiset<>&)): Likewise.
     (operator<=(const multiset<>&, const multiset<>&)): Likewise.
     (operator>=(const multiset<>&, const multiset<>&)): Likewise.
     * include/debug/map.h
     (operator==(const map<>&, const map<>&)): Make inline friend.
     (operator!=(const map<>&, const map<>&)): Likewise.
     (operator<(const map<>&, const map<>&)): Likewise.
     (operator>(const map<>&, const map<>&)): Likewise.
     (operator<=(const map<>&, const map<>&)): Likewise.
     (operator>=(const map<>&, const map<>&)): Likewise.
     * include/debug/multimap.h
     (operator==(const multimap<>&, const multimap<>&)): Make inline friend.
     (operator!=(const multimap<>&, const multimap<>&)): Likewise.
     (operator<(const multimap<>&, const multimap<>&)): Likewise.
     (operator>(const multimap<>&, const multimap<>&)): Likewise.
     (operator<=(const multimap<>&, const multimap<>&)): Likewise.
     (operator>=(const multimap<>&, const multimap<>&)): Likewise.
     * include/debug/set.h
     (operator==(const set<>&, const set<>&)): Make inline friend.
     (operator!=(const set<>&, const set<>&)): Likewise.
     (operator<(const set<>&, const set<>&)): Likewise.
     (operator>(const set<>&, const set<>&)): Likewise.
     (operator<=(const set<>&, const set<>&)): Likewise.
     (operator>=(const set<>&, const set<>&)): Likewise.
     * include/debug/multiset.h
     (operator==(const multiset<>&, const multiset<>&)): Make inline friend.
     (operator!=(const multiset<>&, const multiset<>&)): Likewise.
     (operator<(const multiset<>&, const multiset<>&)): Likewise.
     (operator>(const multiset<>&, const multiset<>&)): Likewise.
     (operator<=(const multiset<>&, const multiset<>&)): Likewise.
     (operator>=(const multiset<>&, const multiset<>&)): Likewise.

Tested under Linux x86_64 normal and debug mode.

When building attached test case the compiler is proposing 73 operator== 
candidates before the patch and 69 after, respectively 69 and 63 in 
Debug mode.

Ok to commit ?

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: assoc_conts_inline_friend_oper.patch
Type: text/x-patch
Size: 44368 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20180927/106a44c0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: all_equality_operators_neg.cc
Type: text/x-c++src
Size: 986 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20180927/106a44c0/attachment-0001.bin>


More information about the Libstdc++ mailing list