std::filesy...m::path::end(3)

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

πŸ’… std::filesy...m::path::end(3) β€” bestie edition πŸ¦‹

okay so this is the std::filesy...m::path::end(3) page from the C++ Standard Libary manual (yes, that's how the header spells it, bestie πŸ’€). It's the begin/end iterator moment for std::filesystem::path, and it's been iconic since C++17 ✨.

πŸŽ€ NAME πŸŽ€

std::filesystem::path::begin,std::filesystem::path::end - std::filesystem::path::begin,std::filesystem::path::end

like, that's the whole name line, and the description is literally the same string again. periodt.

πŸ¦‹ Synopsis πŸ¦‹

iterator begin() const; (1) (since C++17)
iterator end() const;   (2) (since C++17)
  1. Returns an iterator to the first element of the path. If the path is empty, the returned iterator is equal to end().
  2. Returns an iterator one past the last element of the path. Dereferencing this iterator is undefined behavior.
🚨 bestie, dereferencing this iterator is undefined behavior. That's the end() iterator, so don't do it. No cap. πŸ’€

The sequence denoted by this pair of iterators consists of the following:

  1. root-name (if any).
  2. root-directory (if any).
  3. Sequence of file-names, omitting any directory separators.
  4. If there is a directory separator after the last file-name in the path, the last element before the end iterator is an empty element.

🌸 Parameters 🌸

(none)

✨ Return value ✨

  1. Iterator to the first element of the path.
  2. Iterator one past the end of the path

πŸ’œ Exceptions πŸ’œ

May throw implementation-defined exceptions.

πŸ“ Example πŸ“

the page literally says // Run this code, so here's the code, bestie:

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

int main()
{
    const fs::path p =
#   ifdef _WIN32
        "C:\\users\\abcdef\\AppData\\Local\\Temp\\";
#   else
        "/home/user/.config/Cppcheck/Cppcheck-GUI.conf";
#   endif
    std::cout << "Examining the path " << p << " through iterators gives\n";
    for (auto it = p.begin(); it != p.end(); ++it)
        std::cout << *it << " β”‚ ";
    std::cout << '\n';
}

🌈 Possible output 🌈

--- Windows ---
Examining the path "C:\users\abcdef\AppData\Local\Temp\" through iterators gives
"C:" β”‚ "/" β”‚ "users" β”‚ "abcdef" β”‚ "AppData" β”‚ "Local" β”‚ "Temp" β”‚ "" β”‚

--- UNIX ---
Examining the path "/home/user/.config/Cppcheck/Cppcheck-GUI.conf" through iterators gives
"/" β”‚ "home" β”‚ "user" β”‚ ".config" β”‚ "Cppcheck" β”‚ "Cppcheck-GUI.conf" β”‚

okay bye ily πŸ’– source/version: http://cppreference.com; date: 2024.06.10; page: std::filesy...m::path::end(3).

πŸ“¦ where this page comes from