std::experi...emove_suffix(3)

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

okay so bestie, welcome to the std::experi...emove_suffix(3) page from the C++ Standard Libary (yes, that’s the manual name, typo and all πŸ˜­πŸ’…). It’s the std::experimental::basic_string_view::remove_suffix page, and we’re gonna get you fluent, no cap.

πŸ’– NAME πŸ’–

std::experimental::basic_string_view::remove_suffix - std::experimental::basic_string_view::remove_suffix

✨ Synopsis ✨

constexpr void remove_suffix( size_type n );  (library fundamentals TS)

Moves the end of the view back by n characters.

⚠️ warning: the behavior is undefined if n > size().

πŸŽ€ Parameters πŸŽ€

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

🌸 Return value 🌸

(none) β€” that’s it, bestie, there is literally no return value.

πŸ¦‹ Complexity πŸ¦‹

Constant. periodt. ✨

πŸ’œ Example πŸ’œ

Run this code πŸ‘‡

// Run this code

#include <experimental/string_view>
#include <iostream>

int main()
{
    char arr[] = {'a', 'b', 'c', 'd', '\0', '\0', '\0'};
    std::experimental::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)

πŸ’… Category πŸ’…

  • Noindexed pages

xoxo, your Unix bestie πŸ’– β€” this one came from source http://cppreference.com, dated 2024.06.10, and the footer title is std::experi...emove_suffix(3). slay. πŸŽ€

πŸ“¦ where this page comes from