std::filesy..._root_name,(3)

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

🌸 std::filesystem::path::has_root_path, std::filesystem::path::has_root_name β€” a.k.a. the std::filesy..._root_name,(3) page, bestie ✨

Okay so this is from the C++ Standard Library section of the manual, and it's filed under that extremely truncated name std::filesy..._root_name,(3) because apparently the man page author ran out of screen width and just gave up πŸ’€. Anyway, welcome, come sit with me, we're learning about path component checks today and honestly? It's giving "tiny functions, huge convenience." πŸŽ€


πŸ’– NAME

std::filesystem::path::has_root_path, std::filesystem::path::has_root_name, and yes bestie, the full family also includes std::filesystem::path::has_parent_path, std::filesystem::path::has_filename, std::filesystem::path::has_stem, and std::filesystem::path::has_extension.

Literally one big happy function family 🫢


✨ Synopsis

Here's the whole squad, all of them const, all of them bool, all of them living that since C++17 life πŸ‘‘:

bool has_root_path() const;      (1) (since C++17)
bool has_root_name() const;      (2) (since C++17)
bool has_root_directory() const; (3) (since C++17)
bool has_relative_path() const;  (4) (since C++17)
bool has_parent_path() const;    (5) (since C++17)
bool has_filename() const;       (6) (since C++17)
bool has_stem() const;           (7) (since C++17)
bool has_extension() const;      (8) (since C++17)

So what do they all do? They check whether the path actually contains the corresponding path element. That's it. That's the vibe check 🌈

  1. Checks whether root_path() is empty.
  2. Checks whether root_name() is empty.
  3. Checks whether root_directory() is empty.
  4. Checks whether relative_path() is empty.
  5. Checks whether parent_path() is empty.
  6. Checks whether filename() is empty.
  7. Checks whether stem() is empty.
  8. Checks whether extension() is empty.
Ngl the whole pattern is "call the getter, see if it's empty, return the opposite." Elegant. Iconic. No notes. πŸ’…

🌸 Parameters

(none)

Literally nothing. Take no arguments, return a bool, leave. Main character energy fr fr 😭


πŸ¦‹ Return value

true if the corresponding path component is not empty, and false otherwise. Yes bestie, it's inverted from what your brain wants β€” has_ means "not empty," not "is empty." πŸ’€


πŸ”₯ Exceptions

May throw implementation-defined exceptions. So like… it might throw, it might not, and which one depends on your implementation πŸ™ˆ. Stay safe out there.


πŸ“ Example

This section is incomplete.

Reason: no example

Not me showing up to the function page with no example prepared πŸ’€. The category list literally flags it too β€” see below.


🌟 See also

  • empty β€” checks if the path is empty (public member function)

Category:

  • Todo: no example

And that's the page, bestie! πŸ’– Sourced from http://cppreference.com, dated 2024.06.10, filed as std::filesy..._root_name,(3) β€” go forth and check your paths, ily, bye 🧚✨

πŸ“¦ where this page comes from