std::basic_...emove_suffix(3)
π 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
- 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