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

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

✨ NAME ✨

okay so bestie, gather round, because this page is about std::experimental::filesystem::path::begin,std::experimental::filesystem::path::end β€” no wait, I'm not done, the manual then repeats the entire thing again as the description: std::experimental::filesystem::path::begin,std::experimental::filesystem::path::end. yes, twice. the manual said "why say it once when you could say it twice" and honestly? iconic behavior πŸ’…

this is the std::experi...m::path::end(3) page of the C++ Standard Libary manual β€” that ellipsis in the title is carrying the whole team, iykyk 😭


πŸŽ€ Synopsis πŸŽ€

iterator begin() const; (1) (filesystem TS)
iterator end() const;   (2) (filesystem TS)

here's the tea, numbered and everything πŸ”₯

  1. Returns an iterator to the first element of the path. and bestie, listen β€” if the path is empty, the iterator it hands you is equal to end(). empty path = begin meets end, they're the same iterator, it's giving soulmate energy 🫢
  2. Returns an iterator one past the last element of the path. and dereferencing this iterator is undefined behavior β€” do NOT touch it, do NOT peek at it, do NOT *it it. it's the velvet rope at the end of the club, you look at it and that's it πŸ’€

the sequence denoted by this pair of iterators consists of the following, in order, no cap:

  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 a fictitious dot file name. (yes. a fake . β€” it's not even real, it's just there for the vibes 🧚)

🌸 Parameters 🌸

(none)

that's it. that's the section. nothing to see here, no arguments were invited to this party πŸ™ˆ


πŸ’œ 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. so like… your implementation decides, and you just have to live with that uncertainty, bestie 😭


🌈 Example 🌈

// Run this code

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

int main()
{
    fs::path p = "C:\\users\\abcdef\\AppData\\Local\\Temp\\";
    std::cout << "Examining the path " << p << " through iterators gives\n";
    for (auto& e : p)
        std::cout << e << '\n';
}

look at her go β€” a ranged for loop straight over a fs::path, no .begin()/.end() written out, the compiler does it silently like a main character πŸŽ€


⭐ Output ⭐

Examining the path "C:\users\abcdef\AppData\Local\Temp\" through iterators gives
"C:"
"/"
"users"
"abcdef"
"AppData"
"Local"
"Temp"
"."

see that last .? that's the fictitious dot file name from item 4, showing up to say hi 🫢 and "C:" and "/" are the root-name and root-directory doing their thing. the way this path decomposes into little pieces… obsessed πŸ“


πŸ’… Category: πŸ’…

  • * Noindexed pages

that's a wrap, bestie! this lil masterpiece was served fresh from http://cppreference.com on 2024.06.10 β€” go iterate over some paths responsibly, and remember: the end iterator is a look-don't-touch situation βœ¨πŸ’–

πŸ“¦ where this page comes from