std::filesy..._root_name,(3)
πΈ 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 π
- Checks whether
root_path()is empty. - Checks whether
root_name()is empty. - Checks whether
root_directory()is empty. - Checks whether
relative_path()is empty. - Checks whether
parent_path()is empty. - Checks whether
filename()is empty. - Checks whether
stem()is empty. - 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms