std::deque::prepend_range(3)
π std::deque::prepend_range π
okay bestie, welcome to the C++ Standard Libary manual, section 3 β yes, thatβs literally the manual name on the page, no cap π«Ά. Weβre talking about std::deque::prepend_range, and it is giving C++23 range-insertion main character energy β¨.
π NAME π
std::deque::prepend_range - std::deque::prepend_range π
β¨ Synopsis β¨
template< container-compatible-range<T> R > (since C++23)
void prepend_range( R&& rg );
Inserts, in non-reversing order, copies of elements in rg before begin(). Each iterator in the range rg is dereferenced exactly once.
β οΈ All iterators (including the end() iterator) are invalidated. No references are invalidated.
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT
π Type requirements π
Tmust beEmplaceConstructibleintodequefrom*ranges::begin(rg). Also,Tmust beMoveInsertableintodequeandTsatisfiesMoveConstructible,MoveAssignable, andSwappable. Otherwise, the behavior is undefined.
π¦ Return value π¦
(none) β she gives you nothing back, she just does the thing π
π Complexity π
Linear in size of rg.
π Notes π
Feature-test macro check, bestie: the macro is __cpp_lib_containers_ranges, its value is 202202L, the std is (C++23), and the feature is Ranges-aware construction and insertion π₯.
π Example π
// Run this code
#include <algorithm>
#include <cassert>
#include <deque>
#include <vector>
int main()
{
auto container = std::deque{0, 1, 2, 3};
const auto rg = std::vector{-3, -2, -1};
#if __cpp_lib_containers_ranges
container.prepend_range(rg);
#else
container.insert(container.begin(), rg.cbegin(), rg.cend());
#endif
assert(std::ranges::equal(container, std::deque{-3, -2, -1, 0, 1,
2, 3}));
}
π See also π
append_rangeβ adds a range of elements to the end (C++23) (public member function)insert_rangeβ inserts a range of elements (C++23) (public member function)push_frontβ inserts an element to the beginning (public member function)emplace_frontβ constructs an element in-place at the beginning (C++11) (public member function)
mwah π source/version: http://cppreference.com; date: 2024.06.10; page: std::deque::prepend_range(3). Thatβs the footer folded into a cute lil sign-off, bestie π«Ά.
π¦ 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