std::basic_...assign_range(3)
π NAME π
Manual page from C++ Standard Libary for std::basic_...assign_range(3): std::basic_string::assign_range - std::basic_string::assign_range. Yes bestie, the name is the name, and we are literally here for it. π
β¨ Synopsis β¨
This is giving C++23 glow-up, no cap:
template< container-compatible-range<CharT> R > (since C++23)
constexpr std::basic_string& assign_range( R&& rg );
It replaces the contents of the string with the values in the range rg. Iconic behavior, honestly.
Equivalent to:
return assign(
std::basic_string(
std::from_range,
std::forward<R>(rg),
get_allocator())
);
πΈ Parameters πΈ
rgβ a container compatible range. That's the whole vibe: a range that is container compatible, fr fr.
π«Ά Return value π«Ά
*this β that's it, that's the return value. Main character energy returns itself. π
π₯ Complexity π₯
Linear in size of rg. Simple, clean, ate. β¨
π Exceptions π
If the operation would result in size() > max_size(), it throws std::length_error.
If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee). So it's got that strong-safety armor on, periodt. π
π§ Notes π§
Feature-test macro vibe check:
__cpp_lib_containers_rangesβ value:202202L, Std:(C++23), Feature: member functions that accept container compatible range.
π Example π
// Run this code
#include <cassert>
#include <string>
int main()
{
const auto source = {'s', 'o', 'u', 'r', 'c', 'e'};
std::string destination{"destination"};
#ifdef __cpp_lib_containers_ranges
destination.assign_range(source);
#else
destination.assign(source.begin(), source.end());
#endif
assert(destination == "source");
}
π See also π
assignβ assign characters to a string (public member function).operator=β assigns values to the string (public member function).constructorβ constructs abasic_string(public member function).
π mwah, that's the page! Source/version: http://cppreference.com, date: 2024.06.10, and the page is std::basic_...assign_range(3). Byeee π«Ά
π¦ 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