libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

path.io.pass.cpp (2748B)


      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 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <filesystem>
     13 
     14 // class path
     15 
     16 // template <class charT, class traits>
     17 // basic_ostream<charT, traits>&
     18 // operator<<(basic_ostream<charT, traits>& os, const path& p);
     19 //
     20 // template <class charT, class traits>
     21 // basic_istream<charT, traits>&
     22 // operator>>(basic_istream<charT, traits>& is, path& p)
     23 //
     24 
     25 #include "filesystem_include.hpp"
     26 #include <type_traits>
     27 #include <sstream>
     28 #include <cassert>
     29 #include <iostream>
     30 
     31 #include "test_macros.h"
     32 #include "test_iterators.h"
     33 #include "count_new.hpp"
     34 #include "filesystem_test_helper.hpp"
     35 
     36 MultiStringType InStr =  MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
     37 MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");
     38 
     39 
     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 char*)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   static_assert(!is_ostreamable<decltype(std::cout), std::wstring>::value, "");
     87   static_assert(!is_ostreamable<decltype(std::wcout), std::string>::value, "");
     88   static_assert(!is_istreamable<decltype(std::cin), std::wstring>::value, "");
     89   static_assert(!is_istreamable<decltype(std::wcin), std::string>::value, "");
     90 }
     91 
     92 int main() {
     93   doIOTest<char>();
     94   doIOTest<wchar_t>();
     95   //doIOTest<char16_t>();
     96   //doIOTest<char32_t>();
     97   test_LWG2989();
     98 }