[PATCH] __debug::list use C++11 direct initialization
François Dumont
frs.dumont@gmail.com
Tue Oct 16 05:06:00 GMT 2018
On 10/15/2018 12:07 PM, Jonathan Wakely wrote:
> On 09/10/18 07:11 +0200, François Dumont wrote:
>> Here is the communication for my yesterday's patch which I thought
>> svn had failed to commit (I had to interrupt it).
>>
>> Similarly to what I've done for associative containers here is a
>> cleanup of the std::__debug::list implementation leveraging more on
>> C++11 direct initialization.
>>
>> I also made sure we use consistent comparison between
>> iterator/const_iterator in erase and emplace methods.
>>
>> 2018-10-08 François Dumont <fdumont@gcc.gnu.org>
>>
>> Â Â Â * include/debug/list (list<>::cbegin()): Use C++11 direct
>> Â Â Â initialization.
>> Â Â Â (list<>::cend()): Likewise.
>> Â Â Â (list<>::emplace<>(const_iterator, _Args&&...)): Likewise.
>> Â Â Â (list<>::insert(const_iterator, initializer_list<>)): Likewise.
>> Â Â Â (list<>::insert(const_iterator, size_type, const _Tp&)): Likewise.
>> Â Â Â (list<>::erase(const_iterator, const_iterator)): Ensure consistent
>> Â Â Â iterator comparisons.
>> Â Â Â (list<>::splice(const_iterator, list&&, const_iterator,
>> Â Â Â const_iterator)): Likewise.
>>
>> Tested under Linux x86_64 Debug mode and committed.
>>
>> François
>>
>
>> diff --git a/libstdc++-v3/include/debug/list
>> b/libstdc++-v3/include/debug/list
>> index 8add1d596e0..879e1177497 100644
>> --- a/libstdc++-v3/include/debug/list
>> +++ b/libstdc++-v3/include/debug/list
>> @@ -244,11 +244,11 @@ namespace __debug
>> #if __cplusplus >= 201103L
>> Â Â Â Â Â const_iterator
>> Â Â Â Â Â cbegin() const noexcept
>> -Â Â Â Â Â { return const_iterator(_Base::begin(), this); }
>> +Â Â Â Â Â { return { _Base::begin(), this }; }
>>
>> Â Â Â Â Â const_iterator
>> Â Â Â Â Â cend() const noexcept
>> -Â Â Â Â Â { return const_iterator(_Base::end(), this); }
>> +Â Â Â Â Â { return { _Base::end(), this }; }
>
> For functions like emplace (which are C++11-only) and for forward_list
> (also C++11-only) using this syntax makes it clearer.
>
> But for these functions it just makes cbegin() and cend() look
> different to the C++98 begin() and end() functions, for no obvious
> benefit.
>
> Simply using { return end(); } would have been another option.
>
Personnaly I hesitated in writting:
{ return { _Base::cbegin(), this }; }
cause I prefer when you see clearly that Debug implem forward calls to
the Normal implem.
I thought that using C++11 direct init was more likely to have gcc elide
the copy constructor so I used it everywhere possible.
More information about the Libstdc++
mailing list