std::filesy...ry_iterator)(3)
πΈ std::filesystem::begin(directory_iterator) / std::filesystem::end(directory_iterator) πΈ
okay so this is the C++ Standard Libary manual page β yes, that's literally how the header spells it, and we are not fixing it, we are respecting the typo π
β and it's all about the begin / end bestie duo for directory_iterator. periodt.
π NAME π
std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) β and the NAME section literally repeats it: std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator). so that's the whole name vibe, no notes π
β¨ Synopsis β¨
Defined in header <filesystem>
directory_iterator begin( directory_iterator iter ) noexcept; (1)
(since C++17)
directory_iterator end( directory_iterator ) noexcept; (2)
(since C++17)
- Returns
iterunchanged. - Returns a default-constructed
directory_iterator, which serves as the end iterator. The argument is ignored.
These non-member functions enable the use of directory_iterators with range-based for loops and make directory_iterator a range type (since C++20). okay slay, that's the whole point π«Ά
π Parameters π
- iter β a
directory_iterator
π Return value π
iterunchanged.- End iterator (default-constructed
directory_iterator).
π§ Example π§
// Run this code
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
fs::create_directories("sandbox/a/b");
std::ofstream("sandbox/file1.txt");
std::ofstream("sandbox/file2.txt");
for (auto& p : fs::directory_iterator("sandbox"))
std::cout << p << '\n';
fs::remove_all("sandbox");
}
π₯οΈ Possible output π₯οΈ
"sandbox/a"
"sandbox/file1.txt"
"sandbox/file2.txt"
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR LWG 3480 β Applied to C++17; behavior as published:
endtook the argument by reference; correct behavior: takes the argument by value.
π See also π
begin(std::filesystem::recursive_directory_iterator)β range-based for loop supportend(std::filesystem::recursive_directory_iterator)β (function)
okay that's the whole page, bestie π«Ά β source/version: http://cppreference.com, date: 2024.06.10, and the footer tag is std::filesy...ry_iterator)(3). mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms