| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
// Copyright (C) 2013-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#include <testsuite_hooks.h> |
| 21 |
#include <map> |
| 22 |
|
| 23 |
// { dg-do compile { target c++11 } } |
| 24 |
|
| 25 |
// libstdc++/56613 |
| 26 |
|
| 27 |
// A conforming C++03 allocator, should still work in C++11 mode. |
| 28 |
template<typename T> |
| 29 |
struct alloc |
| 30 |
{ |
| 31 |
typedef T value_type; |
| 32 |
typedef T* pointer; |
| 33 |
typedef const T* const_pointer; |
| 34 |
typedef T& reference; |
| 35 |
typedef const T& const_reference; |
| 36 |
typedef unsigned size_type; |
| 37 |
typedef int difference_type; |
| 38 |
|
| 39 |
template<typename U> |
| 40 |
struct rebind { |
| 41 |
typedef alloc<U> other; |
| 42 |
}; |
| 43 |
|
| 44 |
alloc() { } |
| 45 |
template<typename U> |
| 46 |
alloc(const alloc<U>&) { } |
| 47 |
|
| 48 |
pointer allocate(size_type n, const void* = 0) { return |
| 49 |
std::allocator<T>().allocate(n); } |
| 50 |
void deallocate(pointer p, size_type n) { std::allocator<T>().deallocate(p, |
| 51 |
n); } |
| 52 |
|
| 53 |
size_type max_size() const { return -1; } |
| 54 |
|
| 55 |
void construct(pointer p, const T& t) { new ((void*) p) T(t); } |
| 56 |
void destroy(pointer p) { p->~T(); } |
| 57 |
|
| 58 |
pointer address(reference x) const throw() { return &x; } |
| 59 |
const_pointer address(const_reference x) const throw() { return &x; } |
| 60 |
}; |
| 61 |
|
| 62 |
template<typename T, typename U> |
| 63 |
bool operator==(alloc<T>, alloc<U>) { return true; } |
| 64 |
|
| 65 |
template<typename T, typename U> |
| 66 |
bool operator!=(alloc<T>, alloc<U>) { return false; } |
| 67 |
|
| 68 |
int main() |
| 69 |
{ |
| 70 |
std::map<int, int, std::less<int>, alloc<std::pair<const int, int>>> m; |
| 71 |
m[1]; |
| 72 |
} |