GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
* Sign Up! *

Support
Customer Portal
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::stack::push_range(3) C++ Standard Libary std::stack::push_range(3)

std::stack::push_range - std::stack::push_range


template< container-compatible-range<value_type> R > (since C++23)
void push_range( R&& rg );


Inserts a copy of each element of rg in stack, as if by:


* c.append_range(std::forward<R>(rg)) if that is a valid expression (i.e. the
underlying container c has an appropriate append_range member function), or
* ranges::copy(rg, std::back_inserter(c)) otherwise.


Each iterator in the range rg is dereferenced exactly once.


rg - a container compatible range, that is, an input_range whose elements are
convertible to T


(none)


Identical to the complexity of c.append_range or ranges::copy(rg,
std::back_inserter(c)) (depending on what function is used internally).


Feature-test macro Value Std Feature
__cpp_lib_containers_ranges 202202L (C++23) Ranges-aware construction and insertion

// Run this code


#include <algorithm>
#include <iostream>
#include <ranges>
#include <stack>


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::stack<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);
}


1 3 2 4


push inserts element at the top
(public member function)

2024.06.10 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.