forward list patch
François Dumont
francois.cppdevs@free.fr
Wed Oct 27 19:55:00 GMT 2010
Just some other points and I will let you report it to the LWG people.
You said that swap is expected to behave in constant time and I agree.
But I think people are also expecting the swap operation not to
invalidate any iterator. AFAIK this assertion is correct for all
containers, why would it be different for the forward_list ? The only
valid proposition would be to have the before begin iterator swapped
like the other iterators which will impact normal implementation.
On 10/27/2010 03:15 AM, Paolo Carlini wrote:
> If the standard says it can be invalidated it depends on the
> implementation details whether it is or it is not and portable code
> certainly cannot rely on it to be valid. I agree that harmonizing the
> implementation defined behavior of normal-mode and debug-mode is in
> general a good idea, but if that means adding a lot of slow, and ad-hoc,
> and cryptic code, I become very very nervous.
>
Have you taken a look to current _Safe_sequence _M_swap implementation ?
Here it is:
void
_Safe_sequence_base::
_M_swap(_Safe_sequence_base& __x)
{
__gnu_cxx::__scoped_lock sentry(_M_get_mutex());
swap(_M_iterators, __x._M_iterators);
swap(_M_const_iterators, __x._M_const_iterators);
swap(_M_version, __x._M_version);
_Safe_iterator_base* __iter;
for (__iter = _M_iterators; __iter; __iter = __iter->_M_next)
__iter->_M_sequence = this;
for (__iter = __x._M_iterators; __iter; __iter = __iter->_M_next)
__iter->_M_sequence = &__x;
for (__iter = _M_const_iterators; __iter; __iter = __iter->_M_next)
__iter->_M_sequence = this;
for (__iter = __x._M_const_iterators; __iter; __iter = __iter->_M_next)
__iter->_M_sequence = &__x;
}
You see, there are already 4 for loops to swap sequence reference on
each safe iterator, not really a constant operation as long you have
safe iterators pointing to the sequence when the swap operation takes
place. Even if my forward_list _M_swap proposition looks awful it is not
very far from this version. If there is no before begin iterator when
the swap operation takes place then there will be only a couple of
additionnal pointer comparisons compared to this version.
Now I will keep on working on the contention enhancement patch avoiding
tests regarding before begin ownership.
Bests regards
More information about the Libstdc++
mailing list