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

FreeBSD Manual Pages

  
 
  

home | help
std::common...mon_iterator(3) C++ Standard Libarystd::common...mon_iterator(3)

NAME
       std::common_iterator::common_iterator	-   std::common_iterator::com-
       mon_iterator

Synopsis
	  constexpr common_iterator()  requires	 std::default_initializable<I>
       (1) (since C++20)
	  = default;
	  constexpr	     common_iterator(	       I	  i	    );
       (2) (since C++20)
	  constexpr	    common_iterator(	      S		 s	    );
       (3) (since C++20)
	  template< class I2, class S2 >

	  requires	 std::convertible_to<const	 I2&,	    I>	    &&
       (4) (since C++20)
		   std::convertible_to<const S2&, S>

	  constexpr common_iterator( const common_iterator<I2, S2>& x );

	  Constructs a new iterator adaptor, effectively initializes  the  un-
       derlying
	  std::variant<I,  S>  member  object var to hold an I (iterator) or S
       (sentinel) object.

	  1) Default constructor. Default-initializes var. After construction,
       var holds a
	  value-initialized I object. Operations  on  the  resulting  iterator
       adaptor have
	  defined  behavior  if	 and only if the corresponding operations on a
       value-initialized
	  I also have defined behavior.
	  2) After construction, var holds an I	object	move-constructed  from
       i.
	  3)  After  construction, var holds an	S object move-constructed from
       s.
	  4) After construction, var holds an I	or S object  initialized  from
       the I2 or S2 held
	  by  x.var, if	x.var holds that alternative, respectively. The	behav-
       ior is undefined
	  if x is in an	invalid	state, that is,	x.var.valueless_by_exception()
       is equal	to
	  true.

Parameters
	  i - iterator to adapt
	  s - sentinel to adapt
	  x - iterator adaptor to copy

Example
       // Run this code

	#include <algorithm>
	#include <iostream>
	#include <iterator>
	#include <numeric>
	#include <vector>

	int main()
	{
	    std::vector	v{3, 1,	4, 1, 5, 9, 2};

	    using CI = std::common_iterator<
			   std::counted_iterator<std::vector<int>::iterator>,
			   std::default_sentinel_t>;
	    CI unused; // (1)
	    CI	start{std::counted_iterator{std::next(begin(v)),  ssize(v)   -
       2}}; // (2)
	    CI finish{std::default_sentinel}; // (3)
	    CI first{start}; //	(4)
	    CI last{finish}; //	(4)

	    std::copy(first,   last,  std::ostream_iterator<int>{std::cout,  "
       "});
	    std::cout << '\n';

	    std::common_iterator<
		std::counted_iterator<
		    std::ostream_iterator<double>>,
		    std::default_sentinel_t>
		    beg{std::counted_iterator{std::ostream_iterator<dou-
       ble>{std::cout,";  "}, 5}},
		    end{std::default_sentinel};
	    std::iota(beg, end,	3.1);
	    std::cout << '\n';
	}

Output:
	1 4 1 5	9
	3.1;  4.1;  5.1;  6.1;	7.1;

See also
	  operator= assigns another iterator adaptor
	  (C++20)   (public member function)

http://cppreference.com		  2024.06.10	 std::common...mon_iterator(3)

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

home | help