Refactor ix86_expand_vecop_qihi2.
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / modifiers / swap-2.cc
blob9d8b2200e24c7705dcc19b49a76649fb8995565f
1 // { dg-do run { target c++11 } }
3 // Bug 117921 - containers do not use ADL swap for Compare, Pred or Hash types
5 #include <unordered_set>
6 #include <testsuite_hooks.h>
8 namespace adl
10 struct Hash : std::hash<int>
12 static bool swapped;
13 friend void swap(Hash&, Hash&) { swapped = true; }
15 bool Hash::swapped = false;
17 struct Eq : std::equal_to<int>
19 static bool swapped;
20 friend void swap(Eq&, Eq&) { swapped = true; }
22 bool Eq::swapped = false;
24 struct Allocator_base
26 static bool swapped;
28 bool Allocator_base::swapped = false;
30 using std::size_t;
32 template<typename T>
33 struct Allocator : Allocator_base
35 using value_type = T;
37 Allocator() { }
38 template<typename U> Allocator(const Allocator<U>&) { }
40 T* allocate(size_t n) { return std::allocator<T>().allocate(n); }
41 void deallocate(T* p, size_t n) { std::allocator<T>().deallocate(p, n); }
43 using propagate_on_container_swap = std::true_type;
45 friend void swap(Allocator&, Allocator&) { swapped = true; }
46 friend bool operator==(Allocator, Allocator) { return true; }
50 void
51 test_swap()
53 std::unordered_set<int, adl::Eq, adl::Hash, adl::Allocator<int>> s1, s2;
54 s1.swap(s2);
55 VERIFY( adl::Hash::swapped );
56 VERIFY( adl::Eq::swapped );
57 VERIFY( adl::Allocator_base::swapped );
60 int main()
62 test_swap();