Skip to content

Commit

Permalink
<filesystem>: path should be range (#2457)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Guteniev <[email protected]>
Co-authored-by: Casey Carter <[email protected]>
  • Loading branch information
3 people authored Mar 28, 2022
1 parent 3b5d49b commit c302187
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 8 additions & 10 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,7 @@ namespace filesystem {
}

path& operator+=(const path& _Added) { // concat _Added to native()
_Text._Orphan_all();
_Text += _Added._Text;
return *this;
return operator+=(_Added._Text);
}

path& operator+=(const string_type& _Added) { // concat _Added to native()
Expand Down Expand Up @@ -881,23 +879,23 @@ namespace filesystem {

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& operator+=(const _Src& _Added) { // concat _Added to native()
return operator+=(path(_Added));
return operator+=(path(_Added)._Text);
}

template <class _EcharT, enable_if_t<_Is_EcharT<_EcharT>, int> = 0>
path& operator+=(const _EcharT _Added) { // concat _Added to native()
return operator+=(path(&_Added, &_Added + 1));
return operator+=(path(&_Added, &_Added + 1)._Text);
}

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& concat(const _Src& _Added) { // concat _Added to native()
return operator+=(path(_Added));
return operator+=(path(_Added)._Text);
}

template <class _InIt>
path& concat(_InIt _First, _InIt _Last) { // concat [_First, _Last) to native()
static_assert(_Is_EcharT<_Iter_value_t<_InIt>>, "invalid value_type, see N4810 29.11.4 [fs.req]/3");
return operator+=(path(_First, _Last));
return operator+=(path(_First, _Last)._Text);
}

void clear() noexcept { // set *this to the empty path
Expand Down Expand Up @@ -968,7 +966,7 @@ namespace filesystem {
_Text.push_back(L'.');
}

return operator+=(_Replacement);
return operator+=(_Replacement._Text);
}

void swap(path& _Rhs) noexcept {
Expand Down Expand Up @@ -1398,12 +1396,12 @@ namespace filesystem {
}

_NODISCARD friend bool operator==(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) == 0;
return _Left.compare(_Right._Text) == 0;
}

#if _HAS_CXX20
_NODISCARD friend strong_ordering operator<=>(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) <=> 0;
return _Left.compare(_Right._Text) <=> 0;
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD friend bool operator!=(const path& _Left, const path& _Right) noexcept {
Expand Down
5 changes: 5 additions & 0 deletions tests/std/tests/P0896R4_ranges_range_machinery/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <filesystem>
#include <forward_list>
#include <initializer_list>
#include <iostream>
Expand All @@ -31,6 +32,10 @@
// Note that many tests herein assume:
STATIC_ASSERT(std::same_as<std::make_unsigned_t<std::ptrdiff_t>, std::size_t>);

// GH-2358: <filesystem>: path's comparison operators are IF-NDR
static_assert(ranges::range<std::filesystem::path>);
static_assert(ranges::range<const std::filesystem::path>);

template <class T>
concept Decayed = std::same_as<std::decay_t<T>, T>;

Expand Down

0 comments on commit c302187

Please sign in to comment.