std::filesy...ion_pending(3)
π NAME π
okay so bestie, welcome to the manpage for std::filesystem::recursive_directory_iterator::disable_recursion_pending, from the C++ Standard Libary manual β yes, that's literally how the header spells it, missing r and all π. The header also shortens the page name to std::filesy...ion_pending(3), which is giving "we ran out of room but make it fashion." The NAME section is the same long gorgeous name, a dash, and the same long gorgeous name again, because why say it once when you can say it twice? π
std::filesystem::recursive_directory_iterator::disable_recursion_pending
-
std::filesystem::recursive_directory_iterator::disable_recursion_pending
β¨ Synopsis β¨
Since: C++17 π
The signature is exactly this, no cap:
void disable_recursion_pending();
It disables recursion to the currently referred subdirectory, if any β like, if the iterator is looking at a subdir and you're like "nope, not today," this is your move. π«Ά
The call modifies the pending recursion flag on the iterator in such a way that the next time increment is called, the iterator will advance within the current directory even if it is currently referring to a subdirectory that hasn't been visited. That's the whole point, bestie: skip the descent, keep it moving. β¨
The status of the pending recursion flag can be queried with recursion_pending(), which is false after this call. It is reset back to true after increment, and its initial value is also true. So yeah, the flag starts true, gets turned false by this call, and then increment brings it back to true. Little flag, big main-character energy. π
β οΈ The behavior is undefined if *this is the end iterator. That's UB, bestie β not cute, not safe, do not do it. π
π§Έ Parameters π§Έ
(none) β literally no parameters. Slay. π
π« Return value π«
(none) β it returns nothing. It's a void situation, and honestly that's fine. π
π«§ Exceptions π«§
May throw implementation-defined exceptions. So like, your implementation gets to decide the exception drama. π
π Example π
The original literally says // Run this code right before the code, so here's that exact code, bestie:
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
namespace fs = std::filesystem;
int main()
{
fs::current_path(fs::temp_directory_path());
fs::create_directories("sandbox/a/b/c");
fs::create_directories("sandbox/a/b/d/e");
std::ofstream("sandbox/a/b/file1.txt");
fs::create_symlink("a", "sandbox/syma");
std::system("tree sandbox");
for (auto i = fs::recursive_directory_iterator("sandbox");
i != fs::recursive_directory_iterator();
++i)
{
std::cout << std::string(i.depth() * 2, ' ') << *i;
if (fs::is_symlink(i->symlink_status()))
std::cout << " -> " << fs::read_symlink(*i);
std::cout << '\n';
// do not descend into "b"
if (i->path().filename() == "b")
i.disable_recursion_pending();
}
fs::remove_all("sandbox");
}
π¦ Possible output π¦
sandbox
βββ a
β βββ b
β βββ c
β βββ d
β β βββ e
β βββ file1.txt
βββ syma -> a
"sandbox/a"
"sandbox/a/b"
"sandbox/syma" -> "a"
π See also π
recursion_pendingβ checks whether the recursion is disabled for the current directory (public member function). πincrementβ advances to the next entry. β‘οΈoperator++β (public member function). β¨
That's the whole page, bestie. mwah π β source: http://cppreference.com, dated 2024.06.10; the footer also re-stamps std::filesy...ion_pending(3). πβ¨
π¦ 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