Home | History | Annotate | Download | only in unord.map.swap
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <unordered_map>
     11 
     12 // template <class Key, class Value, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, Value>>>
     14 // class unordered_map
     15 
     16 // void swap(unordered_map& x, unordered_map& y);
     17 
     18 #if _LIBCPP_DEBUG >= 1
     19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     20 #endif
     21 
     22 #include <unordered_map>
     23 #include <cassert>
     24 
     25 int main()
     26 {
     27 #if _LIBCPP_DEBUG >= 1
     28     {
     29         typedef std::pair<int, int> P;
     30         P a1[] = {P(1, 1), P(3, 3), P(7, 7), P(9, 9), P(10, 10)};
     31         P a2[] = {P(0, 0), P(2, 2), P(4, 4), P(5, 5), P(6, 6), P(8, 8), P(11, 11)};
     32         std::unordered_map<int, int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     33         std::unordered_map<int, int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
     34         std::unordered_map<int, int>::iterator i1 = c1.begin();
     35         std::unordered_map<int, int>::iterator i2 = c2.begin();
     36         swap(c1, c2);
     37         c1.erase(i2);
     38         c2.erase(i1);
     39         std::unordered_map<int, int>::iterator j = i1;
     40         c1.erase(i1);
     41         assert(false);
     42     }
     43 #endif
     44 }
     45