std::basic_...append_range(3)

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

🌸 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 throws std::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