Add tests for LWG issue #2356. Stability of erasure in unordered associative containers. Libc++ already does this, but now we have tests for it.

llvm-svn: 203494
This commit is contained in:
Marshall Clow 2014-03-10 21:36:36 +00:00
parent 938bc1ea84
commit 17af2f56ab
5 changed files with 144 additions and 1 deletions

View File

@ -21,6 +21,23 @@
#include "min_allocator.h"
#if __cplusplus >= 201103L
template <typename Unordered>
bool only_deletions ( const Unordered &whole, const Unordered &part ) {
typename Unordered::const_iterator w = whole.begin();
typename Unordered::const_iterator p = part.begin();
while ( w != whole.end () && p != part.end()) {
if ( *w == *p )
p++;
w++;
}
return p == part.end();
}
#endif
int main()
{
{
@ -137,5 +154,24 @@ int main()
assert(c.erase(3) == 0);
assert(c.size() == 0);
}
{
typedef std::unordered_map<int, int> C;
C m, m2;
for ( int i = 0; i < 10; ++i ) {
m[i] = i;
m2[i] = i;
}
C::iterator i = m2.begin();
int ctr = 0;
while (i != m2.end()) {
if (ctr++ % 2 == 0)
m2.erase(i++);
else
++i;
}
assert (only_deletions (m, m2));
}
#endif
}

View File

@ -21,6 +21,22 @@
#include "min_allocator.h"
#if __cplusplus >= 201103L
template <typename Unordered>
bool only_deletions ( const Unordered &whole, const Unordered &part ) {
typename Unordered::const_iterator w = whole.begin();
typename Unordered::const_iterator p = part.begin();
while ( w != whole.end () && p != part.end()) {
if ( *w == *p )
p++;
w++;
}
return p == part.end();
}
#endif
int main()
{
{
@ -347,5 +363,26 @@ int main()
assert(std::distance(c.begin(), c.end()) == c.size());
assert(std::distance(c.cbegin(), c.cend()) == c.size());
}
{
typedef std::unordered_multimap<int, int> C;
C m, m2;
for ( int i = 0; i < 10; ++i ) {
for (int j = 0; j < 2; ++j ) {
m.insert (std::make_pair(i,j));
m2.insert(std::make_pair(i,j));
}
}
C::iterator i = m2.begin();
int ctr = 0;
while (i != m2.end()) {
if (ctr++ % 2 == 0)
m2.erase(i++);
else
++i;
}
assert (only_deletions (m, m2));
}
#endif
}

View File

@ -21,6 +21,22 @@
#include "min_allocator.h"
#if __cplusplus >= 201103L
template <typename Unordered>
bool only_deletions ( const Unordered &whole, const Unordered &part ) {
typename Unordered::const_iterator w = whole.begin();
typename Unordered::const_iterator p = part.begin();
while ( w != whole.end () && p != part.end()) {
if ( *w == *p )
p++;
w++;
}
return p == part.end();
}
#endif
int main()
{
{
@ -137,5 +153,24 @@ int main()
assert(c.erase(3) == 0);
assert(c.size() == 0);
}
{
typedef std::unordered_multiset<int> C;
C m, m2;
for ( int i = 0; i < 10; ++i ) {
m.insert(i); m.insert(i);
m2.insert(i); m2.insert(i);
}
C::iterator i = m2.begin();
int ctr = 0;
while (i != m2.end()) {
if (ctr++ % 2 == 0)
m2.erase(i++);
else
++i;
}
assert (only_deletions (m, m2));
}
#endif
}

View File

@ -21,6 +21,22 @@
#include "min_allocator.h"
#if __cplusplus >= 201103L
template <typename Unordered>
bool only_deletions ( const Unordered &whole, const Unordered &part ) {
typename Unordered::const_iterator w = whole.begin();
typename Unordered::const_iterator p = part.begin();
while ( w != whole.end () && p != part.end()) {
if ( *w == *p )
p++;
w++;
}
return p == part.end();
}
#endif
int main()
{
{
@ -136,5 +152,24 @@ int main()
assert(c.erase(3) == 0);
assert(c.size() == 0);
}
{
typedef std::unordered_set<int> C;
C m, m2;
for ( int i = 0; i < 10; ++i ) {
m.insert(i);
m2.insert(i);
}
C::iterator i = m2.begin();
int ctr = 0;
while (i != m2.end()) {
if (ctr++ % 2 == 0)
m2.erase(i++);
else
++i;
}
assert (only_deletions (m, m2));
}
#endif
}

View File

@ -262,7 +262,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2344">2344</a></td><td>quoted()'s interaction with padding is unclear</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2346">2346</a></td><td>integral_constant's member functions should be marked noexcept</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2350">2350</a></td><td>min, max, and minmax should be constexpr</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2356">2356</a></td><td>Stability of erasure in unordered associative containers</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2356">2356</a></td><td>Stability of erasure in unordered associative containers</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2357">2357</a></td><td>Remaining "Assignable" requirement</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2359">2359</a></td><td>How does regex_constants::nosubs affect basic_regex::mark_count()?</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360">2360</a></td><td>reverse_iterator::operator*() is unimplementable</td><td>Issaquah</td><td></td></tr>