[committed] libstdc++: Specialize std::pointer_traits<__normal_iterator<I, C>>

Jonathan Wakely jwakely.gcc@gmail.com
Mon Oct 4 20:30:02 GMT 2021


On Mon, 4 Oct 2021 at 21:28, François Dumont via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On 04/10/21 10:05 pm, François Dumont wrote:
> > On 02/10/21 10:24 pm, Jonathan Wakely wrote:
> >> On Sat, 2 Oct 2021 at 18:27, François Dumont wrote:
> >>> I would like to propose this alternative approach.
> >>>
> >>> In this patch I make __normal_iterator and random iterator
> >>> _Safe_iterator compatible for pointer_traits primary template.
> >>>
> >>> Regarding pointer_traits I wonder if it shouldn't check for the
> >>> to_pointer method availability and use per default: return {
> >>> std::addressof(__e) }; otherwise. This way we wouldn't have to
> >>> provide a
> >>> pointer_to method on __normal_iterator.
> >> But I would rather not have these members present in vector::iterator
> >> and string::iterator, in case users accidentally start to rely on them
> >> being present.
> >
> > Making pointer_traits friends would help but I do not like it neither.
> >
> >
> >>
> >> Another option would be to overload std::__to_address so it knows how
> >> to get the address from __normal_iterator and _Safe_iterator.
> >>
> >> .
> >
> > I start thinking that rather than proposing not-useful and even
> > incorrect code in the case of the _Safe_iterator<> it might be a
> > better approach.
> >
> > Even the rebind for __normal_iterator is a little strange because when
> > doing rebind on std::vector<int>::iterator for long it produces
> > __normal_iterator<long*, std::vector<int>>, quite inconsistent even if
> > useless.
> >
> > But there's something that I'm missing, what is the relation between
> > __addressof and std::pointer_traits ? Is it that __builtin_addressof
> > is using it ?
> >
> Ignore this last question, I realized that we are talking about
> __to_address, not __addressof.

Yes, see the definition of std::__to_address in <bits/ptr_traits.h>
and also PR 96416.


More information about the Libstdc++ mailing list