• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03
11 
12 // <string>
13 
14 // basic_string(basic_string&& str, const Allocator& alloc);
15 
16 #include <string>
17 #include <cassert>
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     LIBCPP_ASSERT(s2.__invariants());
31     LIBCPP_ASSERT(s0.__invariants());
32     assert(s2 == s1);
33     assert(s2.capacity() >= s2.size());
34     assert(s2.get_allocator() == a);
35 }
36 
37 
main()38 int main()
39 {
40     {
41     typedef test_allocator<char> A;
42     typedef std::basic_string<char, std::char_traits<char>, A> S;
43 #if TEST_STD_VER > 14
44     static_assert((noexcept(S{})), "" );
45 #elif TEST_STD_VER >= 11
46     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
47 #endif
48     test(S(), A(3));
49     test(S("1"), A(5));
50     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
51     }
52 
53     int alloc_count = test_alloc_base::alloc_count;
54     {
55     typedef test_allocator<char> A;
56     typedef std::basic_string<char, std::char_traits<char>, A> S;
57 #if TEST_STD_VER > 14
58     static_assert((noexcept(S{})), "" );
59 #elif TEST_STD_VER >= 11
60     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
61 #endif
62     S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
63     S s2 (std::move(s1), A(1));
64     }
65     assert ( test_alloc_base::alloc_count == alloc_count );
66     {
67     typedef min_allocator<char> A;
68     typedef std::basic_string<char, std::char_traits<char>, A> S;
69 #if TEST_STD_VER > 14
70     static_assert((noexcept(S{})), "" );
71 #elif TEST_STD_VER >= 11
72     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
73 #endif
74     test(S(), A());
75     test(S("1"), A());
76     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
77     }
78 }
79