This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Confused by <bits/predefined_ops.h>
On 19/01/17 08:32 +0000, Jonathan Wakely wrote:
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?
This is the alternative I prefer, storing the iterator and
dereferencing as needed:
@@ -207,17 +207,17 @@ namespace __ops
template<typename _Iterator1>
struct _Iter_equals_iter
{
- typename std::iterator_traits<_Iterator1>::reference _M_ref;
+ _Iterator1 _M_it1;
explicit
_Iter_equals_iter(_Iterator1 __it1)
- : _M_ref(*__it1)
+ : _M_it1(__it1)
{ }
template<typename _Iterator2>
bool
operator()(_Iterator2 __it2)
- { return *__it2 == _M_ref; }
+ { return *__it2 == *_M_it1; }
};
template<typename _Iterator>
@@ -273,16 +273,16 @@ namespace __ops
struct _Iter_comp_to_iter
{
_Compare _M_comp;
- typename std::iterator_traits<_Iterator1>::reference _M_ref;
+ _Iterator1 _M_it1;
_Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
- : _M_comp(_GLIBCXX_MOVE(__comp)), _M_ref(*__it1)
+ : _M_comp(_GLIBCXX_MOVE(__comp)), _M_it1(__it1)
{ }
template<typename _Iterator2>
bool
operator()(_Iterator2 __it2)
- { return bool(_M_comp(*__it2, _M_ref)); }
+ { return bool(_M_comp(*__it2, *_M_it1)); }
};
template<typename _Compare, typename _Iterator>