std::basic_...emove_suffix(3)

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

πŸ’… NAME πŸ’…

okay bestie, welcome to the std::basic_...emove_suffix(3) page from the C++ Standard Libary β€” yes, the manual name is literally C++ Standard Libary, typo and all, we're not fixing it ✨

the thing itself is std::basic_string_view::remove_suffix, and the page repeats it like std::basic_string_view::remove_suffix β€” iconic duplication, no notes πŸ’–

✨ Synopsis ✨

constexpr void remove_suffix( size_type n );  (since C++17)

so this is a C++17 joint: moves the end of the view back by n characters πŸŽ€

⚠️ technical caveat, bestie: the behavior is undefined if n > size(). like, not "oopsie" undefined, actual undefined behavior β€” do not pass go, do not collect $200 πŸ’€

🌸 Parameters 🌸

  • n β€” number of characters to remove from the end of the view 🫢

πŸ¦‹ Return value πŸ¦‹

  • (none) β€” literally nothing comes back, it just does its thing and returns nothing πŸ’…

⭐ Complexity ⭐

Constant. that's the whole complexity section, constant, no cap πŸ”₯

πŸŽ€ Example πŸŽ€

the page says // Run this code, so here's the exact example code it points at:

#include <iostream>
#include <string_view>

int main()
{
    char arr[] = {'a', 'b', 'c', 'd', '\0', '\0', '\0'};
    std::string_view v(arr, sizeof arr);
    auto trim_pos = v.find('\0');
    if (trim_pos != v.npos)
        v.remove_suffix(v.size() - trim_pos);
    std::cout << "Array: '" << arr << "', size=" << sizeof arr << '\n'
              << "View : '" << v << "', size=" << v.size() << '\n';
}

🌈 Output 🌈

Array: 'abcd', size=7
View : 'abcd', size=4

πŸ”₯ See also πŸ”₯

  • remove_prefix β€” shrinks the view by moving its start forward (public member function) πŸ‘‘

source: http://cppreference.com Β· version/date: 2024.06.10 Β· footer tag: std::basic_...emove_suffix(3) β€” mwah, bye bestie πŸ’‹βœ¨

πŸ“¦ where this page comes from