path.io.pass.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // UNSUPPORTED: c++98, c++03
  9. // <filesystem>
  10. // class path
  11. // template <class charT, class traits>
  12. // basic_ostream<charT, traits>&
  13. // operator<<(basic_ostream<charT, traits>& os, const path& p);
  14. //
  15. // template <class charT, class traits>
  16. // basic_istream<charT, traits>&
  17. // operator>>(basic_istream<charT, traits>& is, path& p)
  18. //
  19. #include "filesystem_include.hpp"
  20. #include <type_traits>
  21. #include <sstream>
  22. #include <cassert>
  23. #include <iostream>
  24. #include "test_macros.h"
  25. #include "test_iterators.h"
  26. #include "count_new.hpp"
  27. #include "filesystem_test_helper.hpp"
  28. MultiStringType InStr = MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
  29. MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");
  30. template <class CharT>
  31. void doIOTest() {
  32. using namespace fs;
  33. using Ptr = const CharT*;
  34. using StrStream = std::basic_stringstream<CharT>;
  35. const Ptr E = OutStr;
  36. const path p((const char*)InStr);
  37. StrStream ss;
  38. { // test output
  39. auto& ret = (ss << p);
  40. assert(ss.str() == E);
  41. assert(&ret == &ss);
  42. }
  43. { // test input
  44. path p_in;
  45. auto& ret = ss >> p_in;
  46. assert(p_in.native() == (const char*)InStr);
  47. assert(&ret == &ss);
  48. }
  49. }
  50. namespace impl {
  51. using namespace fs;
  52. template <class Stream, class Tp, class = decltype(std::declval<Stream&>() << std::declval<Tp&>())>
  53. std::true_type is_ostreamable_imp(int);
  54. template <class Stream, class Tp>
  55. std::false_type is_ostreamable_imp(long);
  56. template <class Stream, class Tp, class = decltype(std::declval<Stream&>() >> std::declval<Tp&>())>
  57. std::true_type is_istreamable_imp(int);
  58. template <class Stream, class Tp>
  59. std::false_type is_istreamable_imp(long);
  60. } // namespace impl
  61. template <class Stream, class Tp>
  62. struct is_ostreamable : decltype(impl::is_ostreamable_imp<Stream, Tp>(0)) {};
  63. template <class Stream, class Tp>
  64. struct is_istreamable : decltype(impl::is_istreamable_imp<Stream, Tp>(0)) {};
  65. void test_LWG2989() {
  66. static_assert(!is_ostreamable<decltype(std::cout), std::wstring>::value, "");
  67. static_assert(!is_ostreamable<decltype(std::wcout), std::string>::value, "");
  68. static_assert(!is_istreamable<decltype(std::cin), std::wstring>::value, "");
  69. static_assert(!is_istreamable<decltype(std::wcin), std::string>::value, "");
  70. }
  71. int main(int, char**) {
  72. doIOTest<char>();
  73. doIOTest<wchar_t>();
  74. //doIOTest<char16_t>();
  75. //doIOTest<char32_t>();
  76. test_LWG2989();
  77. return 0;
  78. }