]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/allocator/71964.cc
1 // Copyright (C) 2016-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
21 #include <testsuite_hooks.h>
27 using size_type
= unsigned;
30 : moved_to(false), moved_from(false) { }
33 mv_allocator(const mv_allocator
<U
> & a
)
34 : moved_to(a
.moved_to
), moved_from(a
.moved_from
) { }
36 mv_allocator(const mv_allocator
&) = default;
38 mv_allocator(mv_allocator
&& a
) noexcept
: moved_to(true)
43 T
* allocate(unsigned n
) { return std::allocator
<T
>{}.allocate(n
); }
44 void deallocate(T
* p
, unsigned n
) { std::allocator
<T
>{}.deallocate(p
, n
); }
49 #if ! _GLIBCXX_USE_CXX11_ABI
50 // COW string doesn't use allocator_traits, requires C++03 allocator API.
52 using const_pointer
= const T
*;
53 using difference_type
= int;
54 template<typename U
> struct rebind
{ using other
= mv_allocator
<U
>; };
55 void construct(pointer p
, const T
& val
) { ::new(p
) T(val
); }
56 void destroy(pointer p
) { p
->~T(); }
57 size_type
max_size() const { return std::allocator
<T
>().max_size(); }
61 template<typename T
, typename U
>
63 operator==(const mv_allocator
<T
>&, const mv_allocator
<U
>&) { return true; }
65 template<typename T
, typename U
>
67 operator!=(const mv_allocator
<T
>&, const mv_allocator
<U
>&) { return false; }
72 std::basic_string
<char, std::char_traits
<char>, mv_allocator
<char>> s
;
73 auto t
= std::move(s
);
74 VERIFY( s
.get_allocator().moved_from
);
75 VERIFY( t
.get_allocator().moved_to
);