std::basic_...append_range(3)
πΈ NAME πΈ
okay so this is the std::basic_...append_range(3) page from the C++ Standard Libary manual β yes, βLibaryβ is the manual name in the header, bestie, spelling and all ππ
.
The NAME line is literally std::basic_string::append_range - std::basic_string::append_range. Thatβs the function, thatβs the one-liner, iconic.
β¨ Synopsis β¨
Hereβs the signature, and itβs giving C++23:
template< container-compatible-range<CharT> R > (since C++23)
constexpr std::basic_string& append_range( R&& rg );
It appends all characters from the range rg.
Equivalent to:
return append(std::basic_string( std::from_range, std::forward<R>(rg),
get_allocator()));
π― Parameters π―
rgβ a container compatible range. Thatβs it, thatβs the parameter, sheβs simple and powerful β¨.
π Return value π
*thisβ yes, it returns itself, main character energy π.
β±οΈ Complexity β±οΈ
Linear in size of rg. So bigger range = more work, obviously, but itβs linear, no surprises.
π¨ Exceptions π¨
- If the operation would result in
size() > max_size(), it throwsstd::length_error. - If an exception is thrown for any reason, this function has no effect β thatβs the strong exception safety guarantee, bestie. So itβs giving βall or nothingβ π .
π Notes π
Feature-test macro tea β:
- Feature-test macro:
__cpp_lib_containers_ranges - Value / Std:
202202L(C++23) - Feature: member functions that accept container compatible range
π§ͺ Example π§ͺ
Okay, run this code (// Run this code):
#include <cassert>
#include <string>
int main()
{
std::string head{"long long"};
const auto tail = {' ', 'i', 'n', 't'};
#ifdef __cpp_lib_containers_ranges
head.append_range(tail);
#else
head.append(tail.begin(), tail.end());
#endif
assert(head == "long long int");
}
π See also π
appendβ appends characters to the end (public member function). We love a related function, periodt.
Thatβs the whole page, bestie. Source/version/date: http://cppreference.com, 2024.06.10, and the page is std::basic_...append_range(3) β go slay your string appends πβ¨π
π¦ 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