std::filesy...ory_iterator(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is std::filesystem::recursive_directory_iterator::recursive_directory_iterator, straight from the C++ Standard Libary manual β€” yes, the page is literally std::filesy...ory_iterator(3) and the name is a whole mouthful, but we move πŸ’…. It’s the constructor page for std::filesystem::recursive_directory_iterator, and it’s giving β€œlet me build you a recursive directory iterator” energy.


✨ Synopsis ✨

Constructs a new recursive directory iterator. Here are all seven overloads, each one since C++17:

  • recursive_directory_iterator() noexcept; β€” (1), since C++17. Default constructor; constructs an end iterator.
  • recursive_directory_iterator( const recursive_directory_iterator& other ); β€” (2), since C++17. Copy constructor.
  • recursive_directory_iterator( recursive_directory_iterator&& other ) noexcept; β€” (3), since C++17. Move constructor.
  • explicit recursive_directory_iterator( const std::filesystem::path& p ); β€” (4), since C++17.
  • recursive_directory_iterator( const std::filesystem::path& p, std::filesystem::directory_options options ); β€” (5), since C++17.
  • recursive_directory_iterator( const std::filesystem::path& p, std::filesystem::directory_options options, std::error_code& ec ); β€” (6), since C++17.
  • recursive_directory_iterator( const std::filesystem::path& p, std::error_code& ec ); β€” (7), since C++17.

(4)–(7) β€” constructs an iterator that refers to the first entry in the directory that p resolves to.

⚠️ This section is incomplete β€” Reason: errors.

πŸ¦‹ Parameters πŸ¦‹

  • p β€” path to the filesystem object to which the directory iterator will refer.
  • ec β€” out-parameter for error reporting in the non-throwing overloads.
  • options β€” the set of BitmaskType options that control the behavior of the directory iterator.
  • other β€” another directory iterator to use as source to initialize the directory iterator with.

πŸ’€ Exceptions πŸ’€

Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails. no cap, even the β€œchill” ones can still hit an allocation fail 😭.

  • 4,5) β€” throws std::filesystem::filesystem_error on underlying OS API errors, constructed with p as the first path argument and the OS error code as the error code argument.
  • 6,7) β€” sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.

🌸 Notes 🌸

Recursive directory iterators do not follow directory symlinks by default. To enable this behavior, specify directory_options::follow_directory_symlink among the options option set. iykyk 🫢.


πŸŽ€ Example πŸŽ€

⚠️ This section is incomplete β€” Reason: no example.

πŸ‘‘ Defect reports πŸ‘‘

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

  • DR: LWG 3013
  • Applied to: C++17
  • Behavior as published: error_code overload marked noexcept but can allocate memory
  • Correct behavior: noexcept removed

🌈 Categories 🌈

  • Todo with reason
  • Todo no example

signing off with source/version http://cppreference.com, date 2024.06.10, and manual std::filesy...ory_iterator(3) πŸ’œβœ¨ periodt.

πŸ“¦ where this page comes from