]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/allocator/71964.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / 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 // COW strings don't support C++11 allocators:
20 // { dg-require-effective-target cxx11-abi }
21
22 #include <string>
23 #include <testsuite_hooks.h>
24
25 template<typename T>
26 struct mv_allocator
27 {
28 using value_type = T;
29 using size_type = unsigned;
30
31 mv_allocator()
32 : moved_to(false), moved_from(false) { }
33
34 template<typename U>
35 mv_allocator(const mv_allocator<U> & a)
36 : moved_to(a.moved_to), moved_from(a.moved_from) { }
37
38 mv_allocator(const mv_allocator &) = default;
39
40 mv_allocator(mv_allocator && a) noexcept : moved_to(true)
41 {
42 a.moved_from = true;
43 }
44
45 T* allocate(unsigned n) { return std::allocator<T>{}.allcoate(n); }
46 void deallocate(T* p, unsigned n) { std::allocator<T>{}.deallocate(p, n); }
47
48 bool moved_to;
49 bool moved_from;
50 };
51
52 template<typename T, typename U>
53 bool
54 operator==(const mv_allocator<T>&, const mv_allocator<U>&) { return true; }
55
56 template<typename T, typename U>
57 bool
58 operator!=(const mv_allocator<T>&, const mv_allocator<U>&) { return false; }
59
60 void
61 test01()
62 {
63 std::basic_string<char, std::char_traits<char>, mv_allocator<char>> s;
64 auto t = std::move(s);
65 VERIFY( s.get_allocator().moved_from );
66 VERIFY( t.get_allocator().moved_to );
67 }
68
69 int
70 main()
71 {
72 test01();
73 }