Hi
I've been a little bit puzzled by the code in
_Safe_unordered_container::_M_invalidate_all regarding local_iterator
invalidation:
auto __local_end = _M_cont()._M_base().cend(0);
_M_invalidate_local_if(
[__local_end](decltype(__local_end) __it)
{ return __it != __local_end; },
sentry);
Why taking arbitrarily bucket 0 as local_iterator end iterator to avoid
when invalidating ?
Luckily all cend of any bucket will give a local_iterator with _M_cur
node being nullptr and local_iterator, as iterator, only compares this
node pointer for equality.
The end result is that, as shown by the attached test case, the end
local_iterator are never invalidated on a clear.
Is it clearly what the Standard is saying ? I would find it more natural
all local_iterator to be invalidated, no ?
François
// { dg-do run { target c++11 } }
#include <vector>
#include <debug/unordered_map>
#include <testsuite_hooks.h>
void test01()
{
using m_t = __gnu_debug::unordered_map<int, int>;
std::vector<typename m_t::local_iterator> lits;
m_t m =
{
{ 0, 0 },
{ 1, 1 },
{ 2, 2 },
{ 3, 3 },
{ 4, 4 },
{ 5, 5 }
};
for (int i = 0; i != m.bucket_count(); ++i)
{
if (m.bucket_size(i) == 0)
continue;
lits.push_back(m.begin(i));
lits.push_back(m.end(i));
}
m.clear();
for (auto& lit : lits)
{
VERIFY( lit._M_singular() );
}
}
int main()
{
test01();
return 0;
}