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

FreeBSD Manual Pages

  
 
  

home | help
std::ranges...ke_view::end(3) C++ Standard Libarystd::ranges...ke_view::end(3)

NAME
       std::ranges::take_view::end - std::ranges::take_view::end

Synopsis
	  constexpr  auto  end()  requires  (!__SimpleView<V>);		   (1)
       (since C++20)
	  constexpr auto end()	const  requires	 ranges::range<const  V>;  (2)
       (since C++20)

	  Returns  a  sentinel	or  an	iterator  representing	the end	of the
       take_view. The end of
	  the take_view	is either one past the count-th	element	in the	under-
       lying range, or
	  the  end  of	the underlying range if	the latter has less than count
       elements.

	  1) Returns  a	 take_view::/*sentinel*/<false>,  a  std::default_sen-
       tinel_t,	or a
	  ranges::iterator_t<V>.
	  2)  Returns  a  take_view::/*sentinel*/<true>,  a  std::default_sen-
       tinel_t,	or a
	  ranges::iterator_t<const V>.

	  Overload (1) does not	participate in overload	resolution if V	 is  a
       simple view (that
	  is,  if  V and const V are views with	the same iterator and sentinel
       types).

Parameters
	  (none)

Return value
	  The result depends on	the concepts satisfied by possible const-qual-
       ified underlying
	  view type Base_, that	is V (for overload (1))	or const V (for	 over-
       load (2)).

	  Let base_ be the underlying view.

	  The underlying			   random_access_range
	  view satisfies
		...							   yes
       no
			  ranges::begin(base_) +
		      yes
       std::default_sentinel
	  sized_range	  ranges::range_difference_t<Base_>(this->size())
		      no  1) /*sentinel*/<false>{ranges::end(base_)}
			  2) /*sentinel*/<true>{ranges::end(base_)}

Example
       // Run this code

	#include <list>
	#include <ranges>
	#include <iterator>
	#include <iostream>
	#include <type_traits>

	int main() {
	    const auto list1 = { 3, 1, 4, 1, 5 };
	    const auto seq1 = list1 | std::views::take(4);
	    static_assert(std::ranges::sized_range<decltype(seq1)> and
			  std::ranges::random_access_range<decltype(seq1)> and
			  std::is_same_v<decltype(seq1.end()),		   de-
       cltype(list1.end())>);
	    for	 (auto it = seq1.begin(); it !=	seq1.end(); std::cout << *it++
       << ' '){	}
	    std::cout << '\n';

	    std::list list2 = {	2, 7, 1, 8, 2 };
	    const auto seq2 = list2 | std::views::take(4);
	    static_assert(std::ranges::sized_range<decltype(seq2)> and
			  not std::ranges::random_access_range<decltype(seq2)>
       and
			  std::is_same_v<decltype(seq2.end()),	      std::de-
       fault_sentinel_t>);
	    for	  (auto	  it  =	 seq2.begin();	it  !=	std::default_sentinel;
       std::cout << *it++ << ' '){ }
	    std::cout << '\n';
	}

Output:
	3 1 4 1
	2 7 1 8

	 Defect	reports

	  The following	behavior-changing defect reports were applied retroac-
       tively to
	  previously published C++ standards.

	    DR	     Applied	to		   Behavior    as    published
       Correct behavior
	  P2393R1  C++20      implicit conversions between signed and unsigned
       made explicit
			     integer-class types might fail

See also
	  begin		   returns an iterator to the beginning
	  (C++20)	   (public member function)
	  counted_iterator iterator adaptor that tracks	the  distance  to  the
       end of the range
	  (C++20)	   (class template)
	  operator==	    compares a sentinel	with an	iterator returned from
       take_view::begin
	  (C++20)	   (function)

http://cppreference.com		  2022.07.31	 std::ranges...ke_view::end(3)

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

home | help