std::filesy...ve_filename(3)

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

🌸 NAME 🌸

std::filesystem::path::remove_filename β€” and the NAME line is literally std::filesystem::path::remove_filename to std::filesystem::path::remove_filename (repetition ate, no notes πŸ’…). This page is from the C++ Standard Libary manual, and the header shows the very truncated title std::filesy...ve_filename(3) exactly like that. Manual name folded in near the top like a little name tag, bestie. πŸŽ€


✨ Synopsis ✨

Here’s the signature, and yes it’s giving main character energy since C++17:

path& remove_filename();  (since C++17)

remove_filename() removes a single generic-format filename component β€” the thing filename returns β€” from the given generic-format path.

After this function completes, has_filename returns false. Periodt. πŸ’…


🫢 Parameters 🫢

  • (none) β€” no params, no stress, she takes nothing. 😌

πŸ’– Return value πŸ’–

*this β€” that’s it, that’s the return value. 🫢


😭 Exceptions 😭

May throw implementation-defined exceptions. (Not me reading β€œimplementation-defined” and side-eyeing the standard πŸ™ˆ.)


🌈 Example 🌈

       // Run this code

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

        int main()
        {
            fs::path p;
            std::cout << std::boolalpha
                      << (p = "foo/bar").remove_filename() << '\t' <<
       p.has_filename() << '\n'
                      << (p = "foo/").remove_filename() << '\t' <<
       p.has_filename() << '\n'
                      << (p = "/foo").remove_filename() << '\t' <<
       p.has_filename() << '\n'
                      << (p = "/").remove_filename() << '\t' <<
       p.has_filename() << '\n'
                      << (p = "").remove_filename() << '\t' << p.has_filename()
       << '\n';
        }

πŸ’– Output πŸ’–

"foo/"  false
"foo/"  false
"/"     false
"/"     false
""      false

πŸ¦‹ See also πŸ¦‹

  • filename β€” returns the filename path component (public member function). πŸ“
  • replace_filename β€” replaces the last path component with another path (public member function). πŸŽ€
  • has_filename β€” checks if the corresponding path element is not empty (public member function). ✨

made with πŸ’– from http://cppreference.com, dated 2024.06.10 β€” source/version + date, bestie, and that’s the whole footer. bye! πŸ‘‘

πŸ“¦ where this page comes from