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 | // <streambuf> |
| 11 | |
| 12 | // template <class charT, class traits = char_traits<charT> > |
| 13 | // class basic_streambuf; |
| 14 | |
| 15 | // void swap(basic_streambuf& rhs); |
| 16 | |
| 17 | #include <streambuf> |
| 18 | #include <cassert> |
| 19 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 20 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | template <class CharT> |
| 23 | struct test |
| 24 | : public std::basic_streambuf<CharT> |
| 25 | { |
| 26 | typedef std::basic_streambuf<CharT> base; |
| 27 | test() {} |
| 28 | |
| 29 | void swap(test& t) |
| 30 | { |
| 31 | test old_this(*this); |
| 32 | test old_that(t); |
| 33 | base::swap(t); |
| 34 | assert(this->eback() == old_that.eback()); |
| 35 | assert(this->gptr() == old_that.gptr()); |
| 36 | assert(this->egptr() == old_that.egptr()); |
| 37 | assert(this->pbase() == old_that.pbase()); |
| 38 | assert(this->pptr() == old_that.pptr()); |
| 39 | assert(this->epptr() == old_that.epptr()); |
| 40 | assert(this->getloc() == old_that.getloc()); |
| 41 | |
| 42 | assert(t.eback() == old_this.eback()); |
| 43 | assert(t.gptr() == old_this.gptr()); |
| 44 | assert(t.egptr() == old_this.egptr()); |
| 45 | assert(t.pbase() == old_this.pbase()); |
| 46 | assert(t.pptr() == old_this.pptr()); |
| 47 | assert(t.epptr() == old_this.epptr()); |
| 48 | assert(t.getloc() == old_this.getloc()); |
| 49 | return *this; |
| 50 | } |
| 51 | |
| 52 | void setg(CharT* gbeg, CharT* gnext, CharT* gend) |
| 53 | { |
| 54 | base::setg(gbeg, gnext, gend); |
| 55 | } |
| 56 | void setp(CharT* pbeg, CharT* pend) |
| 57 | { |
| 58 | base::setp(pbeg, pend); |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | int main() |
| 63 | { |
| 64 | { |
| 65 | test<char> t; |
| 66 | test<char> t2; |
| 67 | swap(t2, t); |
| 68 | } |
| 69 | { |
| 70 | test<wchar_t> t; |
| 71 | test<wchar_t> t2; |
| 72 | swap(t2, t); |
| 73 | } |
| 74 | { |
| 75 | char g1, g2, g3, p1, p3; |
| 76 | test<char> t; |
| 77 | t.setg(&g1, &g2, &g3); |
| 78 | t.setp(&p1, &p3); |
| 79 | test<char> t2; |
| 80 | swap(t2, t); |
| 81 | } |
| 82 | { |
| 83 | wchar_t g1, g2, g3, p1, p3; |
| 84 | test<wchar_t> t; |
| 85 | t.setg(&g1, &g2, &g3); |
| 86 | t.setp(&p1, &p3); |
| 87 | test<wchar_t> t2; |
| 88 | swap(t2, t); |
| 89 | } |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 90 | std::locale::global(std::locale(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 | { |
| 92 | test<char> t; |
| 93 | test<char> t2; |
| 94 | swap(t2, t); |
| 95 | } |
| 96 | { |
| 97 | test<wchar_t> t; |
| 98 | test<wchar_t> t2; |
| 99 | swap(t2, t); |
| 100 | } |
| 101 | } |