std::experi...emove_prefix(3)

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

πŸŽ€ NAME πŸŽ€

okay so bestie, welcome to the std::experi...emove_prefix(3) page from the C++ Standard Libary manual β€” yes, the header spelling is giving exactly what it's giving, and we're moving on πŸ’–. This page is all about:

  • std::experimental::basic_string_view::remove_prefix
  • std::experimental::basic_string_view::remove_prefix

yep, the NAME section said it twice, no cap β€” twice is the vibe. It's the remove_prefix function for std::experimental::basic_string_view, and it is lowkey iconic for trimming the front of a view.


✨ Synopsis ✨

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

Moves the start of the view forward by n characters. That's the whole plot. πŸ¦‹

⚠️ The behavior is undefined if n > size(). Not "oops maybe", not "try it and see" β€” undefined, bestie. Do not play with that. 😭

🌸 Parameters 🌸

  • n β€” number of characters to remove from the start of the view. Slay, that's the whole parameter.

πŸ’– Return value πŸ’–

  • (none). literally nothing comes back. none energy. 🫢

πŸ¦‹ Complexity πŸ¦‹

  • Constant. no cap, constant. ⭐

πŸ“ Example πŸ“

// Run this code

#include <iostream>
#include <experimental/string_view>
int main()
{
    std::string str = "   trim me";
    std::experimental::string_view v = str;
    v.remove_prefix(std::min(v.find_first_not_of(" "), v.size()));
    std::cout << "String: '" << str << "'\n"
              << "View  : '" << v << "'\n";
}

This is the exact code from the page β€” not me editing it, bestie. It makes a std::string called str with " trim me", makes a std::experimental::string_view called v from it, then calls v.remove_prefix(std::min(v.find_first_not_of(" "), v.size())). Obsessed with that std::min moment, fr fr. πŸ’…

πŸ’… Output πŸ’…

String: '   trim me'
View  : 'trim me'

The string stays all " trim me" with the leading spaces, and the view is "trim me" β€” the prefix got yeeted. πŸŽ€

πŸ‘‘ See also πŸ‘‘

  • remove_suffix β€” shrinks the view by moving its end backward (public member function). The other end's main character moment. 🌈

⭐ Category ⭐

  • Noindexed pages

shoutout to http://cppreference.com β€” the source β€” with date/version 2024.06.10 and page std::experi...emove_prefix(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from