std::experi...emove_prefix(3)
π 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_prefixstd::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
- 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