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