std::filesystem::begin(directory_iterator), std::filesystem::end(directory_iterator)

Header: <filesystem>

  1. Returns iter unchanged.

# Declarations

directory_iterator begin( directory_iterator iter ) noexcept;

(since C++17)

directory_iterator end( directory_iterator ) noexcept;

(since C++17)

# Parameters

# Example

#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");
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3480C++17end took the argument by referencetakes the argument by value

# See also