• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 // <string>
12 
13 // basic_string(basic_string&& str, const Allocator& alloc);
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 
22 
23 template <class S>
24 void
test(S s0,const typename S::allocator_type & a)25 test(S s0, const typename S::allocator_type& a)
26 {
27     S s1 = s0;
28     S s2(std::move(s0), a);
29     LIBCPP_ASSERT(s2.__invariants());
30     LIBCPP_ASSERT(s0.__invariants());
31     assert(s2 == s1);
32     assert(s2.capacity() >= s2.size());
33     assert(s2.get_allocator() == a);
34 }
35 
36 
main(int,char **)37 int main(int, char**)
38 {
39     {
40     typedef test_allocator<char> A;
41     typedef std::basic_string<char, std::char_traits<char>, A> S;
42 #if TEST_STD_VER > 14
43     static_assert((noexcept(S{})), "" );
44 #elif TEST_STD_VER >= 11
45     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
46 #endif
47     test(S(), A(3));
48     test(S("1"), A(5));
49     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
50     }
51 
52     int alloc_count = test_alloc_base::alloc_count;
53     {
54     typedef test_allocator<char> A;
55     typedef std::basic_string<char, std::char_traits<char>, A> S;
56 #if TEST_STD_VER > 14
57     static_assert((noexcept(S{})), "" );
58 #elif TEST_STD_VER >= 11
59     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
60 #endif
61     S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
62     S s2 (std::move(s1), A(1));
63     }
64     assert ( test_alloc_base::alloc_count == alloc_count );
65     {
66     typedef min_allocator<char> A;
67     typedef std::basic_string<char, std::char_traits<char>, A> S;
68 #if TEST_STD_VER > 14
69     static_assert((noexcept(S{})), "" );
70 #elif TEST_STD_VER >= 11
71     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
72 #endif
73     test(S(), A());
74     test(S("1"), A());
75     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
76     }
77 
78   return 0;
79 }
80