diff --git a/libstdc++-v3/include/bits/fs_dir.h b/libstdc++-v3/include/bits/fs_dir.h index d669f2a7468..79dc6764b7b 100644 --- a/libstdc++-v3/include/bits/fs_dir.h +++ b/libstdc++-v3/include/bits/fs_dir.h @@ -39,6 +39,7 @@ #if __cplusplus >= 202002L # include // std::strong_ordering # include // std::default_sentinel_t +# include // enable_view, enable_borrowed_range #endif namespace std _GLIBCXX_VISIBILITY(default) @@ -626,6 +627,27 @@ _GLIBCXX_END_NAMESPACE_CXX11 extern template class __shared_ptr; +#if __glibcxx_ranges // >= C++20 +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// 3480. directory_iterator and recursive_directory_iterator are not ranges +namespace ranges +{ + template<> + inline constexpr bool + enable_borrowed_range = true; + template<> + inline constexpr bool + enable_borrowed_range = true; + + template<> + inline constexpr bool + enable_view = true; + template<> + inline constexpr bool + enable_view = true; +} // namespace ranges +#endif // ranges + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc new file mode 100644 index 00000000000..15e0286fff6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc @@ -0,0 +1,16 @@ +// { dg-do compile { target c++20 } } +// { dg-require-filesystem-ts "" } + +// LWG 3480 +// directory_iterator and recursive_directory_iterator are not C++20 ranges + +#include + +namespace fs = std::filesystem; +namespace rg = std::ranges; + +static_assert( rg::borrowed_range ); +static_assert( rg::borrowed_range ); + +static_assert( rg::view ); +static_assert( rg::view );