]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/set/allocator/71964.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / allocator / 71964.cc
CommitLineData
8d9254fc 1// Copyright (C) 2016-2020 Free Software Foundation, Inc.
8cab3d18
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
52066eae 18// { dg-do run { target c++11 } }
8cab3d18
JW
19
20#include <set>
21#include <testsuite_hooks.h>
22
23template<typename T>
24 struct mv_allocator
25 {
26 using value_type = T;
27 using size_type = unsigned;
28
29 mv_allocator()
30 : moved_to(false), moved_from(false) { }
31
32 template<typename U>
33 mv_allocator(const mv_allocator<U> & a)
34 : moved_to(a.moved_to), moved_from(a.moved_from) { }
35
36 mv_allocator(const mv_allocator &) = default;
37
38 mv_allocator(mv_allocator && a) noexcept : moved_to(true)
39 {
40 a.moved_from = true;
41 }
42
43 T* allocate(unsigned n) { return std::allocator<T>{}.allcoate(n); }
44 void deallocate(T* p, unsigned n) { std::allocator<T>{}.deallocate(p, n); }
45
46 bool moved_to;
47 bool moved_from;
48 };
49
50template<typename T, typename U>
51bool
52operator==(const mv_allocator<T>&, const mv_allocator<U>&) { return true; }
53
54template<typename T, typename U>
55bool
56operator!=(const mv_allocator<T>&, const mv_allocator<U>&) { return false; }
57
58void
59test01()
60{
61 std::set<int, std::less<int>, mv_allocator<int>> s;
62 auto t = std::move(s);
63 VERIFY( s.get_allocator().moved_from );
64 VERIFY( t.get_allocator().moved_to );
65}
66
67int
68main()
69{
70 test01();
71}