1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <string>
11 
12 // basic_string(basic_string&& str, const Allocator& alloc);
13 
14 #include <string>
15 #include <cassert>
16 
17 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
18 
19 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 
23 
24 template <class S>
25 void
test(S s0,const typename S::allocator_type & a)26 test(S s0, const typename S::allocator_type& a)
27 {
28     S s1 = s0;
29     S s2(std::move(s0), a);
30     assert(s2.__invariants());
31     assert(s0.__invariants());
32     assert(s2 == s1);
33     assert(s2.capacity() >= s2.size());
34     assert(s2.get_allocator() == a);
35 }
36 
37 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
38 // #if _LIBCPP_STD_VER <= 14
39 //         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
40 // #else
41 //         _NOEXCEPT;
42 // #endif
43 
main()44 int main()
45 {
46 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
47     {
48     typedef test_allocator<char> A;
49     typedef std::basic_string<char, std::char_traits<char>, A> S;
50 #if TEST_STD_VER > 14
51 	static_assert((noexcept(S{})), "" );
52 #elif TEST_STD_VER >= 11
53 	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
54 #endif
55     test(S(), A(3));
56     test(S("1"), A(5));
57     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
58     }
59 
60     int alloc_count = test_alloc_base::alloc_count;
61     {
62     typedef test_allocator<char> A;
63     typedef std::basic_string<char, std::char_traits<char>, A> S;
64 #if TEST_STD_VER > 14
65 	static_assert((noexcept(S{})), "" );
66 #elif TEST_STD_VER >= 11
67 	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
68 #endif
69     S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
70     S s2 (std::move(s1), A(1));
71     }
72     assert ( test_alloc_base::alloc_count == alloc_count );
73 
74 #if TEST_STD_VER >= 11
75     {
76     typedef min_allocator<char> A;
77     typedef std::basic_string<char, std::char_traits<char>, A> S;
78 #if TEST_STD_VER > 14
79 	static_assert((noexcept(S{})), "" );
80 #elif TEST_STD_VER >= 11
81 	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
82 #endif
83     test(S(), A());
84     test(S("1"), A());
85     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
86     }
87 #endif
88 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
89 }
90