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_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 assert(s2.__invariants());
30 assert(s0.__invariants());
31 assert(s2 == s1);
32 assert(s2.capacity() >= s2.size());
33 assert(s2.get_allocator() == a);
34 }
35
36 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
37
main()38 int main()
39 {
40 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
41 {
42 typedef test_allocator<char> A;
43 typedef std::basic_string<char, std::char_traits<char>, A> S;
44 test(S(), A(3));
45 test(S("1"), A(5));
46 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
47 }
48
49 int alloc_count = test_alloc_base::alloc_count;
50 {
51 typedef test_allocator<char> A;
52 typedef std::basic_string<char, std::char_traits<char>, A> S;
53 S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
54 S s2 (std::move(s1), A(1));
55 }
56 assert ( test_alloc_base::alloc_count == alloc_count );
57
58 #if __cplusplus >= 201103L
59 {
60 typedef min_allocator<char> A;
61 typedef std::basic_string<char, std::char_traits<char>, A> S;
62 test(S(), A());
63 test(S("1"), A());
64 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
65 }
66 #endif
67 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
68 }
69