]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
20067423 2
83ffe9cd 3// Copyright (C) 2014-2023 Free Software Foundation, Inc.
20067423
JW
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.
24template<typename T>
25struct 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.
33template<typename T>
34struct 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)
066f9ea2 48 { std::allocator<T>().deallocate(p.operator->(), n); }
20067423
JW
49};
50
51template<typename T>
52bool operator==(Alloc<T> l, Alloc<T> r) { return true; }
53
54template<typename T>
55bool operator!=(Alloc<T> l, Alloc<T> r) { return false; }
56
57void 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
66int main()
67{
68 test01();
69}