| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
// Bug 117921 - containers do not use ADL swap for Compare, Pred or Hash types |
| 4 |
|
| 5 |
#include <set> |
| 6 |
#include <testsuite_hooks.h> |
| 7 |
|
| 8 |
namespace adl |
| 9 |
{ |
| 10 |
struct Less : std::less<int> |
| 11 |
{ |
| 12 |
static bool swapped; |
| 13 |
friend void swap(Less&, Less&) { swapped = true; } |
| 14 |
}; |
| 15 |
bool Less::swapped = false; |
| 16 |
|
| 17 |
struct Allocator_base |
| 18 |
{ |
| 19 |
static bool swapped; |
| 20 |
}; |
| 21 |
bool Allocator_base::swapped = false; |
| 22 |
|
| 23 |
using std::size_t; |
| 24 |
|
| 25 |
template<typename T> |
| 26 |
struct Allocator : Allocator_base |
| 27 |
{ |
| 28 |
using value_type = T; |
| 29 |
|
| 30 |
Allocator() { } |
| 31 |
template<typename U> Allocator(const Allocator<U>&) { } |
| 32 |
|
| 33 |
T* allocate(size_t n) { return std::allocator<T>().allocate(n); } |
| 34 |
void deallocate(T* p, size_t n) { std::allocator<T>().deallocate(p, n); } |
| 35 |
|
| 36 |
using propagate_on_container_swap = std::true_type; |
| 37 |
|
| 38 |
friend void swap(Allocator&, Allocator&) { swapped = true; } |
| 39 |
friend bool operator==(Allocator, Allocator) { return true; } |
| 40 |
}; |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
test_swap() |
| 45 |
{ |
| 46 |
std::set<int, adl::Less, adl::Allocator<int>> s1, s2; |
| 47 |
s1.swap(s2); |
| 48 |
VERIFY( adl::Less::swapped ); |
| 49 |
VERIFY( adl::Allocator_base::swapped ); |
| 50 |
} |
| 51 |
|
| 52 |
int main() |
| 53 |
{ |
| 54 |
test_swap(); |
| 55 |
} |