From cc64f39d50dcd00b47e0f07dc7d7b9841315930b Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 15 Jan 2022 16:54:32 +0200 Subject: [PATCH 1/3] Untag dispatch _Directory_iterator Towards #189 @miscco would suggest enum instead of bool, so doing it in advance --- stl/inc/experimental/filesystem | 45 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/stl/inc/experimental/filesystem b/stl/inc/experimental/filesystem index 7b0bacf64e..bddd80d829 100644 --- a/stl/inc/experimental/filesystem +++ b/stl/inc/experimental/filesystem @@ -1448,7 +1448,12 @@ private: mutable file_status _Mysymstat; }; -template +enum class _Prefix_directory_t : bool { + _Dont_add, + _Add, +}; + +template <_Prefix_directory_t _Prefix_directory_v> class _Directory_iterator { public: using string_type = path::string_type; @@ -1468,7 +1473,7 @@ public: *_Mypdir = _Open_dir(_Dest, _Path.c_str(), _Errno, _Ftype); if (*_Mypdir) { - _Form_name(_Dest, _Ftype, _Prefix_directory()); + _Form_name(_Dest, _Ftype); } } @@ -1480,7 +1485,7 @@ public: *_Mypdir = _Open_dir(_Dest, _Path.c_str(), _Errno, _Ftype); if (*_Mypdir) { - _Form_name(_Dest, _Ftype, _Prefix_directory()); + _Form_name(_Dest, _Ftype); } _Code = error_code(_Errno, _STD system_category()); @@ -1555,19 +1560,19 @@ private: _Close_dir(*_Mypdir); *_Mypdir = nullptr; // end of directory } else { - _Form_name(_Dest, _Ftype, _Prefix_directory()); + _Form_name(_Dest, _Ftype); } } } - void _Form_name(typename string_type::value_type* _Filename, file_type _Ftype, - true_type) { // set entry to _Mydirpath/_Filename - _Myentry.assign(_Mydirpath / path(_Filename), file_status(_Ftype)); - } - - void _Form_name(typename string_type::value_type* _Filename, file_type _Ftype, - false_type) { // set entry to _Filename - _Myentry.assign(path(_Filename), file_status(_Ftype)); + void _Form_name(typename string_type::value_type* _Filename, file_type _Ftype) { + if constexpr (_Prefix_directory_v == _Prefix_directory_t::_Add) { + // set entry to _Mydirpath/_Filename + _Myentry.assign(_Mydirpath / path(_Filename), file_status(_Ftype)); + } else { + // set entry to _Filename + _Myentry.assign(path(_Filename), file_status(_Ftype)); + } } shared_ptr _Mypdir; @@ -1575,19 +1580,19 @@ private: value_type _Myentry; }; -template +template <_Prefix_directory_t _Prefix_directory_v> _NODISCARD bool operator==( - const _Directory_iterator<_Prefix_directory>& _Left, const _Directory_iterator<_Prefix_directory>& _Right) { + const _Directory_iterator<_Prefix_directory_v>& _Left, const _Directory_iterator<_Prefix_directory_v>& _Right) { return _Left._Equal(_Right); } -template +template <_Prefix_directory_t _Prefix_directory_v> _NODISCARD bool operator!=( - const _Directory_iterator<_Prefix_directory>& _Left, const _Directory_iterator<_Prefix_directory>& _Right) { + const _Directory_iterator<_Prefix_directory_v>& _Left, const _Directory_iterator<_Prefix_directory_v>& _Right) { return !(_Left == _Right); } -using directory_iterator = _Directory_iterator; +using directory_iterator = _Directory_iterator<_Prefix_directory_t::_Add>; _NODISCARD inline const directory_iterator& begin(const directory_iterator& _Iter) noexcept { return _Iter; @@ -1599,7 +1604,7 @@ _NODISCARD inline directory_iterator end(const directory_iterator&) noexcept { class recursive_directory_iterator { public: - using _Myiter = _Directory_iterator; + using _Myiter = _Directory_iterator<_Prefix_directory_t::_Dont_add>; using _Mypair = pair<_Myiter, path>; using string_type = path::string_type; using char_type = string_type::value_type; @@ -2398,7 +2403,7 @@ _NODISCARD inline file_time_type last_write_time(const path& _Path, error_code& _Code.clear(); if (_Ticks == -1) { // report error _Code = make_error_code(errc::operation_not_permitted); - return (file_time_type::min) (); + return (file_time_type::min)(); } return file_time_type(chrono::system_clock::duration(_Ticks)); } @@ -2509,7 +2514,7 @@ inline bool _Remove_all(const path& _Path, uintmax_t& _Ans, error_code& _Code) noexcept { // recursively remove a file or directory, count removed files _Code.clear(); if (is_directory(_Path)) { // empty and remove a directory - using _Myit = _Directory_iterator; + using _Myit = _Directory_iterator<_Prefix_directory_t::_Dont_add>; _Myit _Last; for (;;) { // remove a directory entry From af9f1c73335f270420f20e58a59e7940075f2e5e Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 15 Jan 2022 17:03:22 +0200 Subject: [PATCH 2/3] Old clang-format --- stl/inc/experimental/filesystem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/experimental/filesystem b/stl/inc/experimental/filesystem index bddd80d829..f6bcd214f6 100644 --- a/stl/inc/experimental/filesystem +++ b/stl/inc/experimental/filesystem @@ -2403,7 +2403,7 @@ _NODISCARD inline file_time_type last_write_time(const path& _Path, error_code& _Code.clear(); if (_Ticks == -1) { // report error _Code = make_error_code(errc::operation_not_permitted); - return (file_time_type::min)(); + return (file_time_type::min) (); } return file_time_type(chrono::system_clock::duration(_Ticks)); } From 859445f2850a7e2edeaf6063b8ba238111eac81e Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 18 Feb 2022 13:38:44 -0800 Subject: [PATCH 3/3] Restore ABI. --- stl/inc/experimental/filesystem | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/stl/inc/experimental/filesystem b/stl/inc/experimental/filesystem index bddd80d829..a9c9f20f0b 100644 --- a/stl/inc/experimental/filesystem +++ b/stl/inc/experimental/filesystem @@ -1448,12 +1448,7 @@ private: mutable file_status _Mysymstat; }; -enum class _Prefix_directory_t : bool { - _Dont_add, - _Add, -}; - -template <_Prefix_directory_t _Prefix_directory_v> +template class _Directory_iterator { public: using string_type = path::string_type; @@ -1566,7 +1561,7 @@ private: } void _Form_name(typename string_type::value_type* _Filename, file_type _Ftype) { - if constexpr (_Prefix_directory_v == _Prefix_directory_t::_Add) { + if constexpr (_Prefix_directory::value) { // set entry to _Mydirpath/_Filename _Myentry.assign(_Mydirpath / path(_Filename), file_status(_Ftype)); } else { @@ -1580,19 +1575,19 @@ private: value_type _Myentry; }; -template <_Prefix_directory_t _Prefix_directory_v> +template _NODISCARD bool operator==( - const _Directory_iterator<_Prefix_directory_v>& _Left, const _Directory_iterator<_Prefix_directory_v>& _Right) { + const _Directory_iterator<_Prefix_directory>& _Left, const _Directory_iterator<_Prefix_directory>& _Right) { return _Left._Equal(_Right); } -template <_Prefix_directory_t _Prefix_directory_v> +template _NODISCARD bool operator!=( - const _Directory_iterator<_Prefix_directory_v>& _Left, const _Directory_iterator<_Prefix_directory_v>& _Right) { + const _Directory_iterator<_Prefix_directory>& _Left, const _Directory_iterator<_Prefix_directory>& _Right) { return !(_Left == _Right); } -using directory_iterator = _Directory_iterator<_Prefix_directory_t::_Add>; +using directory_iterator = _Directory_iterator; _NODISCARD inline const directory_iterator& begin(const directory_iterator& _Iter) noexcept { return _Iter; @@ -1604,7 +1599,7 @@ _NODISCARD inline directory_iterator end(const directory_iterator&) noexcept { class recursive_directory_iterator { public: - using _Myiter = _Directory_iterator<_Prefix_directory_t::_Dont_add>; + using _Myiter = _Directory_iterator; using _Mypair = pair<_Myiter, path>; using string_type = path::string_type; using char_type = string_type::value_type; @@ -2514,7 +2509,7 @@ inline bool _Remove_all(const path& _Path, uintmax_t& _Ans, error_code& _Code) noexcept { // recursively remove a file or directory, count removed files _Code.clear(); if (is_directory(_Path)) { // empty and remove a directory - using _Myit = _Directory_iterator<_Prefix_directory_t::_Dont_add>; + using _Myit = _Directory_iterator; _Myit _Last; for (;;) { // remove a directory entry