]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/set/allocator/71964.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / allocator / 71964.cc
1 // Copyright (C) 2016-2018 Free Software Foundation, Inc.
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
18 // { dg-do run { target c++11 } }
19
20 #include <set>
21 #include <testsuite_hooks.h>
22
23 template<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
50 template<typename T, typename U>
51 bool
52 operator==(const mv_allocator<T>&, const mv_allocator<U>&) { return true; }
53
54 template<typename T, typename U>
55 bool
56 operator!=(const mv_allocator<T>&, const mv_allocator<U>&) { return false; }
57
58 void
59 test01()
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
67 int
68 main()
69 {
70 test01();
71 }