std::list::prepend_range(3)
πΈ NAME πΈ
okay bestie, you're on the std::list::prepend_range(3) page from the C++ Standard Libary manual π
β yes, that spelling is in the header, we keep it.
std::list::prepend_range - std::list::prepend_range (the NAME line is literally twins, iconic).
π¦ Synopsis π¦
so the signature is giving:
template< container-compatible-range<T> R > (since C++23)
void prepend_range( R&& rg );
What it does: inserts, in non-reversing order, copies of elements in rg before begin(). Each iterator in the range rg is dereferenced exactly once.
No iterators or references are invalidated. periodt.
π 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 β not a vibe, bestie. Do not test fate.
π Return value π
(none) β literally nothing comes back. it's giving void, and that's fine π
π₯ Complexity π₯
Linear in size of rg. so yeah, it scales with the range, no surprises.
π Notes π
Feature-test macro tea π :
- Feature-test macro:
__cpp_lib_containers_ranges - Value:
202202L - Std:
(C++23) - Feature: Ranges-aware construction and insertion
π Example π
// Run this code
#include <algorithm>
#include <cassert>
#include <list>
#include <vector>
int main()
{
auto container = std::list{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::list{-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.
later, bestie π«Ά β source/version/date: http://cppreference.com Β· 2024.06.10 Β· std::list::prepend_range(3).
π¦ 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