Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // basic_string(basic_string&& str, const Allocator& alloc); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 17 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | |
Marshall Clow | c3deeb5 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 19 | #include "test_allocator.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 20 | #include "min_allocator.h" |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
| 23 | template <class S> |
| 24 | void |
| 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 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 36 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | |
| 38 | int main() |
| 39 | { |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 40 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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)); |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | } |
Marshall Clow | 3dd8846 | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 67 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | } |