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