Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untag dispatch _Directory_iterator #2478

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions stl/inc/experimental/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,12 @@ private:
mutable file_status _Mysymstat;
};

template <class _Prefix_directory>
enum class _Prefix_directory_t : bool {
_Dont_add,
_Add,
};

template <_Prefix_directory_t _Prefix_directory_v>
class _Directory_iterator {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
public:
using string_type = path::string_type;
Expand All @@ -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);
}
}

Expand All @@ -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());
Expand Down Expand Up @@ -1555,39 +1560,39 @@ 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<void*> _Mypdir;
path _Mydirpath;
value_type _Myentry;
};

template <class _Prefix_directory>
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 <class _Prefix_directory>
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<true_type>;
using directory_iterator = _Directory_iterator<_Prefix_directory_t::_Add>;

_NODISCARD inline const directory_iterator& begin(const directory_iterator& _Iter) noexcept {
return _Iter;
Expand All @@ -1599,7 +1604,7 @@ _NODISCARD inline directory_iterator end(const directory_iterator&) noexcept {

class recursive_directory_iterator {
public:
using _Myiter = _Directory_iterator<false_type>;
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;
Expand Down Expand Up @@ -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<false_type>;
using _Myit = _Directory_iterator<_Prefix_directory_t::_Dont_add>;
_Myit _Last;

for (;;) { // remove a directory entry
Expand Down