stream_insert.pass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <string>
  9. // template<class charT, class traits, class Allocator>
  10. // basic_ostream<charT, traits>&
  11. // operator<<(basic_ostream<charT, traits>& os,
  12. // const basic_string_view<charT,traits> str);
  13. #include <string_view>
  14. #include <sstream>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. using std::string_view;
  18. using std::wstring_view;
  19. int main(int, char**)
  20. {
  21. {
  22. std::ostringstream out;
  23. string_view sv("some text");
  24. out << sv;
  25. assert(out.good());
  26. assert(sv == out.str());
  27. }
  28. {
  29. std::ostringstream out;
  30. std::string s("some text");
  31. string_view sv(s);
  32. out.width(12);
  33. out << sv;
  34. assert(out.good());
  35. assert(" " + s == out.str());
  36. }
  37. {
  38. std::wostringstream out;
  39. wstring_view sv(L"some text");
  40. out << sv;
  41. assert(out.good());
  42. assert(sv == out.str());
  43. }
  44. {
  45. std::wostringstream out;
  46. std::wstring s(L"some text");
  47. wstring_view sv(s);
  48. out.width(12);
  49. out << sv;
  50. assert(out.good());
  51. assert(L" " + s == out.str());
  52. }
  53. return 0;
  54. }