Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // void swap(basic_string& s); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <stdexcept> |
| 16 | #include <algorithm> |
| 17 | #include <cassert> |
| 18 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | template <class S> |
| 22 | void |
| 23 | test(S s1, S s2) |
| 24 | { |
| 25 | S s1_ = s1; |
| 26 | S s2_ = s2; |
| 27 | s1.swap(s2); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 28 | assert(s1.__invariants()); |
| 29 | assert(s2.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | assert(s1 == s2_); |
| 31 | assert(s2 == s1_); |
| 32 | } |
| 33 | |
| 34 | int main() |
| 35 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 36 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | typedef std::string S; |
| 38 | test(S(""), S("")); |
| 39 | test(S(""), S("12345")); |
| 40 | test(S(""), S("1234567890")); |
| 41 | test(S(""), S("12345678901234567890")); |
| 42 | test(S("abcde"), S("")); |
| 43 | test(S("abcde"), S("12345")); |
| 44 | test(S("abcde"), S("1234567890")); |
| 45 | test(S("abcde"), S("12345678901234567890")); |
| 46 | test(S("abcdefghij"), S("")); |
| 47 | test(S("abcdefghij"), S("12345")); |
| 48 | test(S("abcdefghij"), S("1234567890")); |
| 49 | test(S("abcdefghij"), S("12345678901234567890")); |
| 50 | test(S("abcdefghijklmnopqrst"), S("")); |
| 51 | test(S("abcdefghijklmnopqrst"), S("12345")); |
| 52 | test(S("abcdefghijklmnopqrst"), S("1234567890")); |
| 53 | test(S("abcdefghijklmnopqrst"), S("12345678901234567890")); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 54 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 55 | #if __cplusplus >= 201103L |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 56 | { |
| 57 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 58 | test(S(""), S("")); |
| 59 | test(S(""), S("12345")); |
| 60 | test(S(""), S("1234567890")); |
| 61 | test(S(""), S("12345678901234567890")); |
| 62 | test(S("abcde"), S("")); |
| 63 | test(S("abcde"), S("12345")); |
| 64 | test(S("abcde"), S("1234567890")); |
| 65 | test(S("abcde"), S("12345678901234567890")); |
| 66 | test(S("abcdefghij"), S("")); |
| 67 | test(S("abcdefghij"), S("12345")); |
| 68 | test(S("abcdefghij"), S("1234567890")); |
| 69 | test(S("abcdefghij"), S("12345678901234567890")); |
| 70 | test(S("abcdefghijklmnopqrst"), S("")); |
| 71 | test(S("abcdefghijklmnopqrst"), S("12345")); |
| 72 | test(S("abcdefghijklmnopqrst"), S("1234567890")); |
| 73 | test(S("abcdefghijklmnopqrst"), S("12345678901234567890")); |
| 74 | } |
| 75 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | } |