Confused by <bits/predefined_ops.h>

Jonathan Wakely jwakely@redhat.com
Thu Jan 19 08:32:00 GMT 2017


On 18/01/17 22:17 +0100, François Dumont wrote:
>Hi
>
>Names of functions and struct in this file are surely not what I am 
>most proud of in libstdc++. I even think that I confess it when I 
>proposed the patch :-)
>
>As those elements are purely internal and we rarely need to be touch I 
>don't consider it as a big issue but if you want to rename everything 
>don't hesitate.
>
>Note that I also have this patch pending:
>
>https://gcc.gnu.org/ml/libstdc++/2015-10/msg00071.html
>
>But I can surely rework it on top of your changes unless you just want 
>me to forget it.

It looks good, let's return to it in stage 1 for gcc 8.

Any thoughts on the questions repeated below?

As for PR78346, I can fix it by making the relevant function object
types take their constructor arguments by reference, so that the
reference we store in _M_ref is bound to some iterator in the caller's
scope, not the constructor argument that goes out of scope immediately
(see patch below). But why do those objects store a reference anyway?
Why don't they just store the iterator passed to the constructor and
dereference it as needed? Is this to avoid dereferencing multiple
times?  Because that might be slow?


@@ -210,7 +210,7 @@ namespace __ops
       typename std::iterator_traits<_Iterator1>::reference _M_ref;
 
       explicit
-      _Iter_equals_iter(_Iterator1 __it1)
+      _Iter_equals_iter(_Iterator1& __it1)
        : _M_ref(*__it1)
       { }
 
@@ -222,7 +222,7 @@ namespace __ops
 
   template<typename _Iterator>
     inline _Iter_equals_iter<_Iterator>
-    __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
+    __iter_comp_iter(_Iter_equal_to_iter, _Iterator& __it)
     { return _Iter_equals_iter<_Iterator>(__it); }
 
   template<typename _Predicate>
@@ -275,7 +275,7 @@ namespace __ops
       _Compare _M_comp;
       typename std::iterator_traits<_Iterator1>::reference _M_ref;
 
-      _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
+      _Iter_comp_to_iter(_Compare __comp, _Iterator1& __it1)
        : _M_comp(_GLIBCXX_MOVE(__comp)), _M_ref(*__it1)
       { }
 
@@ -287,7 +287,7 @@ namespace __ops
 
   template<typename _Compare, typename _Iterator>
     inline _Iter_comp_to_iter<_Compare, _Iterator>
-    __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
+    __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator& __it)
     {
       return _Iter_comp_to_iter<_Compare, _Iterator>(
          _GLIBCXX_MOVE(__comp._M_comp), __it);



More information about the Libstdc++ mailing list