move_assign.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <fstream>
  11. // template <class charT, class traits = char_traits<charT> >
  12. // class basic_filebuf
  13. // basic_filebuf& operator=(basic_filebuf&& rhs);
  14. #include <fstream>
  15. #include <cassert>
  16. #include "platform_support.h"
  17. int main()
  18. {
  19. std::string temp = get_temp_file_name();
  20. {
  21. std::filebuf f;
  22. assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
  23. | std::ios_base::trunc) != 0);
  24. assert(f.is_open());
  25. assert(f.sputn("123", 3) == 3);
  26. f.pubseekoff(1, std::ios_base::beg);
  27. assert(f.sgetc() == '2');
  28. std::filebuf f2;
  29. f2 = move(f);
  30. assert(!f.is_open());
  31. assert(f2.is_open());
  32. assert(f2.sgetc() == '2');
  33. }
  34. std::remove(temp.c_str());
  35. {
  36. std::wfilebuf f;
  37. assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
  38. | std::ios_base::trunc) != 0);
  39. assert(f.is_open());
  40. assert(f.sputn(L"123", 3) == 3);
  41. f.pubseekoff(1, std::ios_base::beg);
  42. assert(f.sgetc() == L'2');
  43. std::wfilebuf f2;
  44. f2 = move(f);
  45. assert(!f.is_open());
  46. assert(f2.is_open());
  47. assert(f2.sgetc() == L'2');
  48. }
  49. std::remove(temp.c_str());
  50. }