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

FreeBSD Manual Pages

  
 
  

home | help
std::forwar..._range_after(3) C++ Standard Libarystd::forwar..._range_after(3)

NAME
       std::forward_list::insert_range_after	  -	std::forward_list::in-
       sert_range_after

Synopsis
	  template< container-compatible-range<T> R  >			(since
       C++23)
	  iterator insert_range_after( const_iterator pos, R&& rg );

	  Inserts, in non-reversing order, the copies of elements in rg	before
       pos. Each
	  iterator in the range	rg is dereferenced exactly once.

	  pos  must  be	 any  dereferenceable  iterator	in the range [begin(),
       end()) or the
	  before_begin() iterator (thus, end() is not  a  valid	 argument  for
       pos).

	  No iterators or references become invalidated.

	  The behavior is undefined if rg overlaps with	the container.

Parameters
	  pos	      -	       an iterator after which the content will	be in-
       serted
	  rg	     -	     a container compatible range,  that  is,  an  in-
       put_range whose
			     elements are convertible to T

Type requirements
	  -
	  T  must  be EmplaceConstructible into	forward_list from *ranges::be-
       gin(rg).	Otherwise,
	  the behavior is undefined.

Return value
	  An iterator that points at the copy of  the  last  element  inserted
       into forward_list
	  or at	pos if rg is empty.

Complexity
	  Linear in size of rg.

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 <cassert>
	#include <forward_list>
	#include <iterator>
	#include <vector>

	int main()
	{
	    auto container = std::forward_list{1, 2, 3,	4};
	    auto pos = std::next(container.cbegin());
	    assert(*pos	== 2);
	    const auto rg = std::vector{-1, -2,	-3};

	#ifdef __cpp_lib_containers_ranges
	    container.insert_range_after(pos, rg);
	#else
	    container.insert_after(pos,	rg.cbegin(), rg.cend());
	#endif

	    assert(std::ranges::equal(container, std::vector{1,	2, -1, -2, -3,
       3, 4}));
	}

See also
	  prepend_range	adds a range of	elements to the	beginning
	  (C++23)	(public	member function)
	  insert_after	inserts	elements after an element
			(public	member function)
	  emplace_after	constructs elements in-place after an element
			(public	member function)

http://cppreference.com		  2024.06.10	 std::forwar..._range_after(3)

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

home | help