blob: 0b74ef05b4f8dc9cac603eeae9101b33d4e9104a [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// template<class charT, class traits, class Allocator>
13// void swap(basic_string<charT,traits,Allocator>& lhs,
14// basic_string<charT,traits,Allocator>& rhs);
15
16#include <string>
17#include <stdexcept>
18#include <algorithm>
19#include <cassert>
20
21template <class S>
22void
23test(S s1, S s2)
24{
25 S s1_ = s1;
26 S s2_ = s2;
27 swap(s1, s2);
28 assert(s1.__invariants());
29 assert(s2.__invariants());
30 assert(s1 == s2_);
31 assert(s2 == s1_);
32}
33
34int main()
35{
36 typedef std::string S;
37 test(S(""), S(""));
38 test(S(""), S("12345"));
39 test(S(""), S("1234567890"));
40 test(S(""), S("12345678901234567890"));
41 test(S("abcde"), S(""));
42 test(S("abcde"), S("12345"));
43 test(S("abcde"), S("1234567890"));
44 test(S("abcde"), S("12345678901234567890"));
45 test(S("abcdefghij"), S(""));
46 test(S("abcdefghij"), S("12345"));
47 test(S("abcdefghij"), S("1234567890"));
48 test(S("abcdefghij"), S("12345678901234567890"));
49 test(S("abcdefghijklmnopqrst"), S(""));
50 test(S("abcdefghijklmnopqrst"), S("12345"));
51 test(S("abcdefghijklmnopqrst"), S("1234567890"));
52 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
53}