std::stack<T,Container>::push_range
From cppreference.com
template< container-compatible-range<value_type> R >
void push_range( R&& rg );
|
(since C++23) (constexpr since C++26) |
|
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 containerchas an appropriateappend_rangemember function), orranges::copy(rg, std::back_inserter(c))otherwise.
Each iterator in the range rg is dereferenced exactly once.
Parameters
| rg | - | a container compatible range, that is, an input_range whose elements are convertible to T
|
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 | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | Ranges-aware construction and insertion |
Example
Run this code
#include <initializer_list>
#include <stack>
#include <print>
int main()
{
std::stack<int> adaptor;
const auto rg = {1, 3, 2, 4};
adaptor.push_range(rg);
std::println("{}", adaptor);
}
Output:
[1, 3, 2, 4]
See also
| inserts element at the top (public member function) |