std::filesy...y_iterator),(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::filesystem::begin(recursive_directory_iterator) πŸ’…

okay bestie, welcome to the manual page for std::filesystem::begin(recursive_directory_iterator) from the C++ Standard Libary β€” yes, the header spells it C++ Standard Libary, and the page tag is the chopped-up std::filesy...y_iterator),(3), and we are keeping the lore πŸ’–.

✨ NAME ✨

std::filesystem::begin(recursive_directory_iterator), - std::filesystem::begin(recursive_directory_iterator),

yes, it repeats itself. the NAME line is doing its little duplicate thing, and honestly? we respect it 🫢.

🌸 Synopsis 🌸

defined in header <filesystem> β€” that's home base, bestie:

Defined in header <filesystem>

recursive_directory_iterator begin( recursive_directory_iterator iter ) noexcept;
recursive_directory_iterator end( recursive_directory_iterator ) noexcept;
  • (1) (since C++17) β€” labels the begin line.
  • (2) (since C++17) β€” labels the end line.
  1. Returns iter unchanged.
  2. Returns a default-constructed recursive_directory_iterator, which serves as the end iterator. The argument is ignored.

These non-member functions enable the use of recursive_directory_iterators with range-based for loops and make recursive_directory_iterator a range type (since C++20). range energy activated ✨.

πŸŽ€ Parameters πŸŽ€

  • iter β€” a recursive_directory_iterator

πŸ’– Return value πŸ’–

  1. iter unchanged.
  2. End iterator (default-constructed recursive_directory_iterator).

πŸ¦‹ Example πŸ¦‹

here's the whole demo, no cap:

// Run this code

#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;

int main()
{
    fs::current_path(fs::temp_directory_path());
    fs::create_directories("sandbox/a/b");
    std::ofstream("sandbox/file1.txt");
    fs::create_symlink("a", "sandbox/syma");

    std::cout << "Print dir structure using OS specific command 'tree':\n";
    std::system("tree --noreport sandbox");

    std::cout << "\nPrint dir structure using directory iterator:\n";
    for (auto& p : fs::recursive_directory_iterator("sandbox"))
        std::cout << p << '\n';

    fs::remove_all("sandbox");
}

🌈 Possible output 🌈

Print dir structure using OS specific command 'tree':
sandbox
β”œβ”€β”€ a
β”‚   └── b
β”œβ”€β”€ file1.txt
└── syma -> a

Print dir structure using directory iterator:
"sandbox/syma"
"sandbox/file1.txt"
"sandbox/a"
"sandbox/a/b"

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • LWG 3480 β€” applied to C++17; behavior as published: end took the argument by reference; correct behavior: takes the argument by value.

πŸ‘‘ See also πŸ‘‘

  • begin(std::filesystem::directory_iterator) β€” range-based for loop support
  • end(std::filesystem::directory_iterator) β€” (function) (C++17)

mwah πŸ’‹ this page came from http://cppreference.com, version/date 2024.06.10, and it's filed under std::filesy...y_iterator),(3). stay hydrated and may your iterators be valid 🫢✨

πŸ“¦ where this page comes from