blob: cee538800dd0baed0e03aa611439e82fc113a754 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
Howard Hinnant6e0a1f42010-08-22 00:47:54 +000012// template<class charT, class traits, class Allocator>
13// void swap(basic_string<charT,traits,Allocator>& lhs,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014// basic_string<charT,traits,Allocator>& rhs);
15
16#include <string>
17#include <stdexcept>
18#include <algorithm>
19#include <cassert>
20
Marshall Clow061d0cc2013-11-26 20:58:02 +000021#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000022
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023template <class S>
24void
25test(S s1, S s2)
26{
27 S s1_ = s1;
28 S s2_ = s2;
29 swap(s1, s2);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030 assert(s1.__invariants());
31 assert(s2.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032 assert(s1 == s2_);
33 assert(s2 == s1_);
34}
35
36int main()
37{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000038 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039 typedef std::string S;
40 test(S(""), S(""));
41 test(S(""), S("12345"));
42 test(S(""), S("1234567890"));
43 test(S(""), S("12345678901234567890"));
44 test(S("abcde"), S(""));
45 test(S("abcde"), S("12345"));
46 test(S("abcde"), S("1234567890"));
47 test(S("abcde"), S("12345678901234567890"));
48 test(S("abcdefghij"), S(""));
49 test(S("abcdefghij"), S("12345"));
50 test(S("abcdefghij"), S("1234567890"));
51 test(S("abcdefghij"), S("12345678901234567890"));
52 test(S("abcdefghijklmnopqrst"), S(""));
53 test(S("abcdefghijklmnopqrst"), S("12345"));
54 test(S("abcdefghijklmnopqrst"), S("1234567890"));
55 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000056 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070057#if __cplusplus >= 201103L
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000058 {
59 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
60 test(S(""), S(""));
61 test(S(""), S("12345"));
62 test(S(""), S("1234567890"));
63 test(S(""), S("12345678901234567890"));
64 test(S("abcde"), S(""));
65 test(S("abcde"), S("12345"));
66 test(S("abcde"), S("1234567890"));
67 test(S("abcde"), S("12345678901234567890"));
68 test(S("abcdefghij"), S(""));
69 test(S("abcdefghij"), S("12345"));
70 test(S("abcdefghij"), S("1234567890"));
71 test(S("abcdefghij"), S("12345678901234567890"));
72 test(S("abcdefghijklmnopqrst"), S(""));
73 test(S("abcdefghijklmnopqrst"), S("12345"));
74 test(S("abcdefghijklmnopqrst"), S("1234567890"));
75 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
76 }
77#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078}