| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
#include <set> |
| 4 |
#include <testsuite_allocator.h> |
| 5 |
|
| 6 |
// An allocator that uses __gnu_cxx::_Pointer_adapter as its pointer type. |
| 7 |
template class std::set<int, std::less<int>, |
| 8 |
__gnu_test::CustomPointerAlloc<int>>; |
| 9 |
|
| 10 |
// Unlike __gnu_cxx::_Pointer_adapter, this fancy pointer supports neither |
| 11 |
// implicit nor explicit conversions from raw pointers. The constructor from |
| 12 |
// a raw pointer is explicit and requires a second parameter. The only way for |
| 13 |
// containers to construct one of these pointers is pointer_traits::pointer_to. |
| 14 |
template<typename T> |
| 15 |
struct Pointer : __gnu_test::PointerBase<Pointer<T>, T> |
| 16 |
{ |
| 17 |
using Base = __gnu_test::PointerBase<Pointer<T>, T>; |
| 18 |
|
| 19 |
Pointer() = default; |
| 20 |
Pointer(std::nullptr_t) : Base() { } |
| 21 |
explicit Pointer(T* p, int) : Base(p) { } |
| 22 |
|
| 23 |
// Allow conversions to const_pointer and to void_pointer |
| 24 |
template<typename U, typename = typename std::enable_if< |
| 25 |
(!std::is_const<U>::value && std::is_same<T, const U>::value) |
| 26 |
|| (std::is_void<T>::value && std::is_convertible<U*, T*>::value) |
| 27 |
>::type> |
| 28 |
Pointer(const Pointer<U>& p) : Base(p.operator->()) { } |
| 29 |
|
| 30 |
template<typename U> |
| 31 |
static typename std::enable_if<std::is_same<U, T>::value, Pointer>::type |
| 32 |
pointer_to(U& t) |
| 33 |
{ return Pointer(std::addressof(t), 1); } |
| 34 |
}; |
| 35 |
|
| 36 |
// A minimal allocator that uses Pointer as its pointer type. |
| 37 |
template<typename T> |
| 38 |
struct Allocator |
| 39 |
{ |
| 40 |
using value_type = T; |
| 41 |
using pointer = Pointer<T>; |
| 42 |
|
| 43 |
Allocator() = default; |
| 44 |
template<typename U> |
| 45 |
Allocator(const Allocator<U>&) { } |
| 46 |
|
| 47 |
pointer allocate(std::size_t n) |
| 48 |
{ return pointer(std::allocator<T>().allocate(n), 1); } |
| 49 |
|
| 50 |
void deallocate(pointer p, std::size_t n) |
| 51 |
{ |
| 52 |
std::allocator<T>().deallocate(p.operator->(), n); |
| 53 |
} |
| 54 |
|
| 55 |
bool operator==(const Allocator&) const { return true; } |
| 56 |
bool operator!=(const Allocator&) const { return false; } |
| 57 |
}; |
| 58 |
|
| 59 |
template class std::set<int, std::less<int>, Allocator<int>>; |
| 60 |
|
| 61 |
#include <testsuite_iterators.h> |
| 62 |
|
| 63 |
void |
| 64 |
test_template_members(__gnu_test::input_container<short>& c) |
| 65 |
{ |
| 66 |
// Use member functions that are not included in explicit instantiations. |
| 67 |
std::set<int, std::less<int>, Allocator<int>> s(c.begin(), c.end()); |
| 68 |
s.emplace(1); |
| 69 |
s.emplace_hint(s.begin(), 1); |
| 70 |
s.insert(c.begin(), c.end()); |
| 71 |
|
| 72 |
#ifdef __cpp_lib_node_extract |
| 73 |
std::set<int, std::greater<int>, Allocator<int>> s1; |
| 74 |
s.merge(s1); |
| 75 |
std::multiset<int, std::greater<int>, Allocator<int>> m1; |
| 76 |
s.merge(m1); |
| 77 |
#endif |
| 78 |
|
| 79 |
#ifdef __cpp_lib_ranges_to_container |
| 80 |
short arr[2]; |
| 81 |
__gnu_test::test_input_range<short> r(arr); |
| 82 |
std::set<int, std::less<int>, Allocator<int>> s2(std::from_range, r); |
| 83 |
std::set<int, std::less<int>, Allocator<int>> s3(std::from_range, r, |
| 84 |
Allocator<int>{}); |
| 85 |
s2.insert_range(r); |
| 86 |
#endif |
| 87 |
} |