std::experi...parent_path(3)

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

πŸ’– std::experi...parent_path(3) πŸ’–

okay so welcome to the std::experi...parent_path(3) page from the C++ Standard Libary manual β€” yes bestie, that's the manual name, typo and all, and I folded it in up here instead of copy-pasting the whole header line. This one is all about std::experimental::filesystem::path::parent_path, and it's lowkey iconic. πŸ’…


🌸 NAME 🌸

  • std::experimental::filesystem::path::parent_path β€” std::experimental::filesystem::path::parent_path

the original name line does the double-repeat thing, so we're keeping that energy fr fr 🫢

✨ Synopsis ✨

path parent_path() const;  (filesystem TS)

Okay so this is the filesystem TS version, no cap. It returns the path to the parent directory. But plot twist: it returns an empty path if empty() or there's only a single element in the path β€” specifically when begin() == --end(). 😭

The resulting path is constructed by appending all elements in the range [begin(), --end()) to an empty path. That's the whole construction vibe, periodt. ✨

πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally no parameters, she takes none, slay.

🌈 Return value 🌈

The path to the parent directory. That's it, that's the return value, main character energy. πŸ‘‘

πŸ’€ Exceptions πŸ’€

May throw implementation-defined exceptions. Translation: the implementation gets to decide, so don't come for me if it throws β€” that's the caveat and we're keeping it crystal clear. 🫢

πŸ¦‹ Example πŸ¦‹

// Run this code

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

int main()
{
    for (fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

Possible output:

The parent path of "/var/tmp/example.txt" is "/var/tmp"
The parent path of "/" is ""
The parent path of "/var/tmp/." is "/var/tmp"

πŸ‘€ See also πŸ‘€

This section is incomplete β€” bestie, they literally left it blank, not me. πŸ™ˆ

πŸ“ Categories πŸ“

  • Noindexed pages
  • Todo without reason

source/version/date sign-off: this page comes from http://cppreference.com, dated 2024.06.10, and its footer handle is std::experi...parent_path(3) β€” folded into this cute little sign-off instead of copy-pasted, mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from