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

Marshall Clow mclow.lists at gmail.com
Mon Mar 10 14:36:37 PDT 2014


Author: marshall
Date: Mon Mar 10 16:36:36 2014
New Revision: 203494

URL: http://llvm.org/viewvc/llvm-project?rev=203494&view=rev
Log:
Add tests for LWG issue #2356. Stability of erasure in unordered associative containers. Libc++ already does this, but now we have tests for it.

Modified:
    libcxx/trunk/test/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp
    libcxx/trunk/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp
    libcxx/trunk/test/containers/unord/unord.multiset/erase_key.pass.cpp
    libcxx/trunk/test/containers/unord/unord.set/erase_key.pass.cpp
    libcxx/trunk/www/cxx1y_status.html

Modified: libcxx/trunk/test/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp?rev=203494&r1=203493&r2=203494&view=diff
==============================================================================
--- libcxx/trunk/test/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp (original)
+++ libcxx/trunk/test/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp Mon Mar 10 16:36:36 2014
@@ -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
 }

Modified: libcxx/trunk/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp?rev=203494&r1=203493&r2=203494&view=diff
==============================================================================
--- libcxx/trunk/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp (original)
+++ libcxx/trunk/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp Mon Mar 10 16:36:36 2014
@@ -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
 }

Modified: libcxx/trunk/test/containers/unord/unord.multiset/erase_key.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/unord/unord.multiset/erase_key.pass.cpp?rev=203494&r1=203493&r2=203494&view=diff
==============================================================================
--- libcxx/trunk/test/containers/unord/unord.multiset/erase_key.pass.cpp (original)
+++ libcxx/trunk/test/containers/unord/unord.multiset/erase_key.pass.cpp Mon Mar 10 16:36:36 2014
@@ -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
 }

Modified: libcxx/trunk/test/containers/unord/unord.set/erase_key.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/unord/unord.set/erase_key.pass.cpp?rev=203494&r1=203493&r2=203494&view=diff
==============================================================================
--- libcxx/trunk/test/containers/unord/unord.set/erase_key.pass.cpp (original)
+++ libcxx/trunk/test/containers/unord/unord.set/erase_key.pass.cpp Mon Mar 10 16:36:36 2014
@@ -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
 }

Modified: libcxx/trunk/www/cxx1y_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1y_status.html?rev=203494&r1=203493&r2=203494&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1y_status.html (original)
+++ libcxx/trunk/www/cxx1y_status.html Mon Mar 10 16:36:36 2014
@@ -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>





More information about the cfe-commits mailing list