Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::queue::push_range(3)     C++ Standard Libary    std::queue::push_range(3)

NAME
       std::queue::push_range -	std::queue::push_range

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 expres-
       sion (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.

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

Return value
	  (none)

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

Notes
	      Feature-test macro       Value	Std		      Feature
	  __cpp_lib_containers_ranges 202202L (C++23)  Ranges-aware  construc-
       tion 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 Adap-
       tor::Container c;
	    {
		auto const& container()	const {	return this->c;	}
	    };

	    for	 (auto	const&	elem  :	 static_cast<const   Container&>(adap-
       tor).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)

http://cppreference.com		  2024.06.10	     std::queue::push_range(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::queue::push_range&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help