std::queue::push_range(3)
std::queue::push_range π
Ok bestie, this is the std::queue::push_range(3) page from the C++ Standard Library, and itβs giving very βnew C++23 feature just droppedβ energy. π«Ά
β¨ NAME β¨
std::queue::push_rangeβ literallystd::queue::push_range. Thatβs the whole name, bestie.
π¦ Synopsis π¦
template< container-compatible-range<value_type> R > (since C++23)
void push_range( R&& rg );
Inserts a copy of each element of rg in queue, as if by:
c.append_range(std::forward<R>(rg))if that is a valid expression (i.e. the underlying containerchas an appropriateappend_rangemember function), orranges::copy(rg, std::back_inserter(c))otherwise.
Each iterator in the range rg is dereferenced exactly once. No cap. π
πΈ Parameters πΈ
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
π Return value π
- (none) β yeah, it gives nothing back, and thatβs the vibe.
π₯ Complexity π₯
Identical to the complexity of c.append_range or ranges::copy(rg, std::back_inserter(c)) (depending on what function is used internally).
β Notes β
Feature-test macro time, bestie:
__cpp_lib_containers_rangesβ value202202L, std(C++23), feature: Ranges-aware construction and insertion.
π§ Example π§
// Run this code
#include <algorithm>
#include <iostream>
#include <ranges>
#include <queue>
template<typename Adaptor>
requires (std::ranges::input_range<typename Adaptor::container_type>)
void println(auto, const Adaptor& adaptor)
{
struct Container : Adaptor // gain access to protected Adaptor::Container c;
{
auto const& container() const { return this->c; }
};
for (auto const& elem : static_cast<const Container&>(adaptor).container())
std::cout << elem << ' ';
std::cout << '\n';
}
int main()
{
std::queue<int> adaptor;
const auto rg = {1, 3, 2, 4};
#ifdef __cpp_lib_containers_ranges
adaptor.push_range(rg);
#else
std::ranges::for_each(rg, [&adaptor](auto e){ adaptor.push(e); });
#endif
println("{}", adaptor);
}
π Output π
1 3 2 4
π See also π
pushβ inserts element at the end (public member function). Slay.
Thatβs the whole page, bestie π«Ά β source: http://cppreference.com, version/date vibes: 2024.06.10, and the manual is std::queue::push_range(3). Periodt. π
π¦ 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