forked from OSchip/llvm-project
[libc++] LWG3171: implement operator<< for filesystem::directory_entry.
Differential Revision: https://reviews.llvm.org/D116642
This commit is contained in:
parent
cf35825388
commit
b6d87773fe
|
@ -17,7 +17,7 @@
|
|||
"`3120 <https://wg21.link/LWG3120>`__","Unclear behavior of ``monotonic_buffer_resource::release()``","November 2020","",""
|
||||
"`3170 <https://wg21.link/LWG3170>`__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","November 2020","",""
|
||||
"`3036 <https://wg21.link/LWG3036>`__","``polymorphic_allocator::destroy`` is extraneous","November 2020","",""
|
||||
"`3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","November 2020","",""
|
||||
"`3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","November 2020","|Complete|","14.0"
|
||||
"`3306 <https://wg21.link/LWG3306>`__","``ranges::advance`` violates its preconditions","November 2020","","","|ranges|"
|
||||
"`3403 <https://wg21.link/LWG3403>`__","Domain of ``ranges::ssize(E)`` doesn't ``match ranges::size(E)``","November 2020","","","|ranges|"
|
||||
"`3404 <https://wg21.link/LWG3404>`__","Finish removing subrange's conversions from pair-like","November 2020","","","|ranges|"
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
|
@ -23,6 +23,7 @@
|
|||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iosfwd>
|
||||
#include <system_error>
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
|
@ -239,6 +240,12 @@ public:
|
|||
return __p_ >= __rhs.__p_;
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) {
|
||||
return __os << __d.path();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class directory_iterator;
|
||||
friend class recursive_directory_iterator;
|
||||
|
|
|
@ -89,6 +89,8 @@ int main(int, char**) {
|
|||
test<char, const char *, wchar_t> ('X', chars, chars+10, L"0X1X2X3X4X5X6X7X8X9");
|
||||
test<char, const int *, wchar_t> ('x', ints, ints+10, L"10x11x12x13x14x15x16x17x18x19");
|
||||
#endif
|
||||
// TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized
|
||||
// character type (see https://llvm.org/PR53119).
|
||||
// test<char, const char *, char16_t>('X', chars, chars+10, u"0X1X2X3X4X5X6X7X8X9");
|
||||
// test<char, const int *, char16_t>('x', ints, ints+10, u"10x11x12x13x14x15x16x17x18x19");
|
||||
// test<char, const char *, char32_t>('X', chars, chars+10, U"0X1X2X3X4X5X6X7X8X9");
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03
|
||||
// UNSUPPORTED: libcpp-has-no-localization
|
||||
|
||||
// <filesystem>
|
||||
//
|
||||
// class directory_entry
|
||||
//
|
||||
// template<class charT, class traits>
|
||||
// friend basic_ostream<charT, traits>&
|
||||
// operator<<(basic_ostream<charT, traits>& os, const directory_entry& d);
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "make_string.h"
|
||||
|
||||
MultiStringType InStr = MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
|
||||
MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");
|
||||
|
||||
template <class CharT>
|
||||
void TestOutput() {
|
||||
const char* input = static_cast<const char*>(InStr);
|
||||
const CharT* expected_output = static_cast<const CharT*>(OutStr);
|
||||
const fs::directory_entry dir = fs::directory_entry(fs::path(input));
|
||||
std::basic_stringstream<CharT> stream;
|
||||
|
||||
auto& result = stream << dir;
|
||||
assert(stream.str() == expected_output);
|
||||
assert(&result == &stream);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
TestOutput<char>();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
TestOutput<wchar_t>();
|
||||
#endif
|
||||
// TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized character
|
||||
// type (see https://llvm.org/PR53119).
|
||||
//TestOutput<char8_t>();
|
||||
//TestOutput<char16_t>();
|
||||
//TestOutput<char32_t>();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -94,6 +94,8 @@ int main(int, char**) {
|
|||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
doIOTest<wchar_t>();
|
||||
#endif
|
||||
// TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized character
|
||||
// type (see https://llvm.org/PR53119).
|
||||
//doIOTest<char16_t>();
|
||||
//doIOTest<char32_t>();
|
||||
test_LWG2989();
|
||||
|
|
Loading…
Reference in New Issue