]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / allocate_hint_nonpod.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2014-2022 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 <memory>
21 #include <testsuite_allocator.h>
22
23 // User-defined pointer type with non-trivial destructor.
24 template<typename T>
25 struct Pointer : __gnu_test::PointerBase<Pointer<T>, T>
26 {
27 using __gnu_test::PointerBase<Pointer<T>, T>::PointerBase;
28
29 ~Pointer() { /* non-trivial */ }
30 };
31
32 // Minimal allocator with user-defined pointer type.
33 template<typename T>
34 struct Alloc
35 {
36 typedef T value_type;
37 typedef Pointer<T> pointer;
38
39 Alloc() = default;
40
41 template<typename U>
42 Alloc(const Alloc<U>&) { }
43
44 pointer allocate(std::size_t n) // does not take a hint
45 { return pointer(std::allocator<T>().allocate(n)); }
46
47 void deallocate(pointer p, std::size_t n)
48 { std::allocator<T>().deallocate(p.operator->(), n); }
49 };
50
51 template<typename T>
52 bool operator==(Alloc<T> l, Alloc<T> r) { return true; }
53
54 template<typename T>
55 bool operator!=(Alloc<T> l, Alloc<T> r) { return false; }
56
57 void test01()
58 {
59 typedef std::allocator_traits<Alloc<int>> traits_type;
60 traits_type::allocator_type a;
61 traits_type::const_void_pointer v;
62 traits_type::pointer p = traits_type::allocate(a, 1, v);
63 traits_type::deallocate(a, p, 1);
64 }
65
66 int main()
67 {
68 test01();
69 }