Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -4337,6 +4337,20 @@ namespace filesystem {
return _STD filesystem::copy(_From, _To, copy_options::none);
}
} // namespace filesystem

#ifdef __cpp_lib_concepts
namespace ranges {
template <>
inline constexpr bool enable_borrowed_range<filesystem::directory_iterator> = true;
template <>
inline constexpr bool enable_borrowed_range<filesystem::recursive_directory_iterator> = true;
template <>
inline constexpr bool enable_view<filesystem::directory_iterator> = true;
template <>
inline constexpr bool enable_view<filesystem::recursive_directory_iterator> = true;
} // namespace ranges
#endif // __cpp_lib_concepts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint to other reviewers: our end overloads for directory_iterator and recursive_directory_iterator already take their argument by value as in the proposed resolution of LWG-3480. In fact they always have, all the way back to MSVC-PR-108103! I'll have to thank Gor for realizing that WG21 would want to change these 3.5 years later =)

[No change requested.]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested, noting for the record: These explicit specializations work because the primary templates are defined in <xutility>:

STL/stl/inc/xutility

Lines 1972 to 1973 in 3c2fd04

template <class>
inline constexpr bool enable_borrowed_range = false;

STL/stl/inc/xutility

Lines 2696 to 2698 in 3c2fd04

template <class _Ty>
inline constexpr bool enable_view =
derived_from<_Ty, view_base> || _Derived_from_specialization_of<_Ty, view_interface>;

_STD_END

#pragma pop_macro("new")
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ tests\GH_002120_streambuf_seekpos_and_seekoff
tests\LWG2597_complex_branch_cut
tests\LWG3018_shared_ptr_function
tests\LWG3422_seed_seq_ctors
tests\LWG3480_directory_iterator_range
tests\P0019R8_atomic_ref
tests\P0024R2_parallel_algorithms_adjacent_difference
tests\P0024R2_parallel_algorithms_adjacent_find
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/LWG3480_directory_iterator_range/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_latest_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <filesystem>
#include <ranges>

using namespace std::filesystem;
using namespace std::ranges;

bool is_tiff(const directory_entry& entry) {
return entry.is_regular_file() && entry.path().extension().native() == L"tiff";
}

void test(directory_iterator dir) {
[[maybe_unused]] auto tif_files = dir | views::filter(is_tiff);
[[maybe_unused]] auto first_5_files = dir | views::take(5);
static_assert(borrowed_range<directory_iterator>);
}

void test_recursive(recursive_directory_iterator dir) {
[[maybe_unused]] auto tif_files = dir | views::filter(is_tiff);
[[maybe_unused]] auto first_5_files = dir | views::take(5);
static_assert(borrowed_range<recursive_directory_iterator>);
}

int main() {} // COMPILE-ONLY