std::forwar...epend_range(3)
πΈ std::forward_list::prepend_range β C++ Standard Library, section 3 πΈ
π NAME π
std::forward_list::prepend_range β yes bestie, that's the whole name: std::forward_list::prepend_range. We're so back.
β¨ SYNOPSIS β¨
template< container-compatible-range<T> R > (since C++23)
void prepend_range( R&& rg );
Okay so picture this: prepend_range inserts, in non-reversing order, copies of the elements in rg before begin(). Every iterator in the range rg gets dereferenced exactly once β not twice, not "oops I did it again" twice. And the best part? No iterators or references are invalidated. Iconic behavior, honestly.
π¦ PARAMETERS π¦
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
π§ TYPE REQUIREMENTS π§
Tmust beEmplaceConstructibleintoforward_listfrom*ranges::begin(rg). Otherwise, the behavior is undefined. And bestie, "undefined behavior" is not a cute vibe β it's a real warning. π
π RETURN VALUE π
(none) β literally nothing comes back. It's giving "do the thing and leave", and honestly? Respect.
π COMPLEXITY π
Linear in size of rg. No cap.
π₯ NOTES π₯
Feature-test macro check, because C++23 said "new feature, who dis?":
- 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 <forward_list>
#include <vector>
int main()
{
auto container = std::forward_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_after(container.before_begin(), rg.cbegin(),
rg.cend());
#endif
assert(std::ranges::equal(container, std::forward_list{-3, -2, -1,
0, 1, 2, 3}));
}
π SEE ALSO π
insert_rangeβ inserts a range of elements(C++23)(public member function).insert_range_afterβ inserts a range of elements after an element(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 (public member function).
π that's the whole vibe β sourced from http://cppreference.com, dated 2024.06.10. bye bestie, go slay some ranges! π
β¨
π¦ 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