std::forward_list optim for always equal allocator
François Dumont
frs.dumont@gmail.com
Mon Sep 11 20:36:00 GMT 2017
On 11/09/2017 14:11, Jonathan Wakely wrote:
> On 11/09/17 07:44 +0200, Daniel Krügler wrote:
>> 2017-09-11 7:12 GMT+02:00 François Dumont <frs.dumont@gmail.com>:
>>> When user declare a container iterator like that:
>>>
>>> std::forward_list<int>::iterator it;
>>>
>>> There is no reason to initialize it with a null node pointer. It is
>>> just an
>>> uninitialized iterator which is invalid to use except to initialize it.
>>
>> While that is correct, for every forward iterator (and
>> std::forward_list<int>::iterator meets these requirements), it is also
>> required that a value-initialized iterator can be compared against
>> other initialized iterators, so this reduces the amount of freedom to
>> define a default constructor for such iterators even when used to
>> default-initialize. This is not meant as a showstopper argument, since
>> I have not fully understood of what you are planning, but just a
>> reminder.
>
> Right, which means that
> std::forward_list<int>::iterator it = {};
>
> must initialize the node pointer to nullptr. If we remove the
> initialization of _Fwd_list_iterator<T>::_M_node from the default
> constructor then it would be left uninitialized.
>
> But I'm confused, François was talking about removing the
> initialization of _Fwd_list_node_base::_M_next, what has that got to
> do with forward_list<T>::iterator? Thee is no node-base in the
> iterator.
>
> So I'm still wondering why the initialization of _M_next should be
> removed.
>
Indeed, the iterator contains a _Fwd_list_node_base*.
So my remark was rather for the:
_Fwd_list_iterator() noexcept
: _M_node() { }
that could simply be
_Fwd_list_iterator() = default;
no ?
François
More information about the Libstdc++
mailing list