std::vector::append_range(3)
π¦ std::vector::append_range(3) π¦
okay bestie, welcome to the C++ Standard Libary page for std::vector::append_range β yes, the manual name says βLibary,β and we respect the canon π
. This is your C++23 era, and it's giving βappend a whole range, not just one lil elementβ energy β¨.
πΈ NAME πΈ
std::vector::append_rangeβstd::vector::append_range. Like, the name is the name, no cap π.
β¨ Synopsis β¨
template< container-compatible-range<T> R > (since C++23)
constexpr void append_range( R&& rg );
It inserts copies of the elements from the range rg before end(), in non-reversing order. Periodt.
If, after the operation, the new size() is greater than the old capacity(), a reallocation takes place. When that happens, all iterators (including the end() iterator) and all references to the elements are invalidated. Otherwise, only the end() iterator is invalidated. Each iterator in rg is dereferenced exactly once β once, bestie, not extra π
.
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
π§ Type requirements π§
Tmust beEmplaceConstructibleintovectorfrom*ranges::begin(rg). Also,Tmust beMoveInsertableintovector. Otherwise, the behavior is undefined.
π¨ undefined behavior is not the vibe. not slay. do not collect $200.
π Return value π
(none) β literally nothing returned, it's giving void energy π«Ά.
π₯ Complexity π₯
If reallocation happens, linear in the number of elements of the resulting vector; otherwise, linear in the number of elements inserted plus the distance to the end().
π Exceptions π
If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T, or by any InputIterator operation, there are no effects.
If an exception is thrown while inserting a single element at the end and T is CopyInsertable or std::is_nothrow_move_constructible_v<T> is true, there are no effects.
Otherwise, if an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.
π Notes π
Feature-test macro vibe check:
__cpp_lib_containers_rangesβ value202202L, std(C++23), feature: Ranges-aware construction and insertion.
π Example π
Run this code, bestie:
#include <algorithm>
#include <cassert>
#include <vector>
#include <list>
int main()
{
auto head = std::vector{1, 2, 3, 4};
const auto tail = std::list{-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::vector{1, 2, 3, 4, -5, -6,
-7}));
}
π See also π
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).
okay thatβs the whole page, bestie π«Ά source: http://cppreference.com, version/date: 2024.06.10, for std::vector::append_range(3) β mwah, slay, bye π
π¦ 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