std::list::append_range(3)
π std::list::append_range(3) π
okay bestie, welcome to the C++ Standard Libary manual β yes, the header spells it βLibaryβ and we are respecting the lore. This page is all about std::list::append_range, and she is lowkey iconic. π
πΈ NAME πΈ
std::list::append_rangeβ thatβs literally the name:std::list::append_range.
β¨ Synopsis β¨
template< container-compatible-range<T> R > (since C++23)
void append_range( R&& rg );
Inserts copies of elements from the range rg before end(), in non-reversing order.
No iterators or references are invalidated.
Each iterator in rg is dereferenced exactly once.
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
π§ Type requirements π§
Tmust beEmplaceConstructibleintolistfrom*ranges::begin(rg). Otherwise, the behavior is undefined.
π«Ά Return value π«Ά
(none) β literally nothing, bestie. No notes.
π Complexity π
Linear in size of rg. The number of calls to the constructor of T is exactly equal to the std::ranges::size(rg)).
π¨ Exceptions π¨
If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee). Periodt. π‘οΈ
π§ Notes π§
Feature-test macro:
__cpp_lib_containers_rangesβ value202202L, Std(C++23), feature: Ranges-aware construction and insertion.
π Example π
// Run this code
#include <algorithm>
#include <cassert>
#include <list>
#include <vector>
int main()
{
auto head = std::list{1, 2, 3, 4};
const auto tail = std::vector{-5, -6, -7};
#ifdef __cpp_lib_containers_ranges
head.append_range(tail);
#else
head.insert(head.end(), tail.cbegin(), tail.cend());
#endif
assert(std::ranges::equal(head, std::list{1, 2, 3, 4, -5, -6,
-7}));
}
π See also π
prepend_rangeβ adds a range of elements to the beginning (C++23) (public member function).insert_rangeβ inserts a range of elements (C++23) (public member function).push_backβ adds an element to the end (public member function).emplace_backβ constructs an element in-place at the end (C++11) (public member function).
source/version: cppreference.com, 2024.06.10. k bye bestie, go append that range responsibly. πβ¨π
π¦ 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