Files
cppdraft_translate/cppdraft/range/slide/view.md
2025-10-25 03:02:53 +03:00

9.7 KiB
Raw Blame History

[range.slide.view]

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.30 Slide view [range.slide]

25.7.30.2 Class template slide_view [range.slide.view]

🔗

namespace std::ranges {templateconcept slide-caches-nothing = random_access_range && sized_range; // exposition onlytemplateconcept slide-caches-last = // exposition onlyslide-caches-nothing && bidirectional_range && common_range; templateconcept slide-caches-first = // exposition onlyslide-caches-nothing && slide-caches-last; template<forward_range V>requires viewclass slide_view : public view_interface<slide_view> { V base_; // exposition only range_difference_t n_; // exposition only// [range.slide.iterator], class template slide_view::iteratortemplate class iterator; // exposition only// [range.slide.sentinel], class slide_view::sentinelclass sentinel; // exposition onlypublic:constexpr explicit slide_view(V base, range_difference_t n); constexpr V base() const & requires copy_constructible { return base_; }constexpr V base() && { return std::move(base_); }constexpr auto begin()requires (!(simple-view && slide-caches-nothing)); constexpr auto begin() const requires slide-caches-nothing; constexpr auto end()requires (!(simple-view && slide-caches-nothing)); constexpr auto end() const requires slide-caches-nothing; constexpr auto size() requires sized_range; constexpr auto size() const requires sized_range; constexpr auto reserve_hintsize() requires approximately_sized_range; constexpr auto reserve_hintsize() const requires approximately_sized_range; }; template slide_view(R&&, range_difference_t) -> slide_view<views::all_t>;}

🔗

constexpr explicit slide_view(V base, range_difference_t<V> n);

1

#

Preconditions: n > 0 is true.

2

#

Effects: Initializes base_ with std::move(base) andn_ with n.

🔗

constexpr auto begin() requires (!([simple-view](range.utility.helpers#concept:simple-view "25.5.2Helper concepts[range.utility.helpers]")<V> && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2Class template slide_­view[range.slide.view]")<const V>));

3

#

Returns:

If V models slide-caches-first,iterator(ranges::begin(base_), ranges::next(ranges::begin(base_), n_ - 1, ranges::end(base_)), n_)

Otherwise, iterator(ranges::begin(base_), n_).

4

#

Remarks: In order to provide the amortized constant-time complexity required by the range concept, this function caches the result within the slide_view for use on subsequent calls when V models slide-caches-first.

🔗

constexpr auto begin() const requires [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2Class template slide_­view[range.slide.view]")<const V>;

5

#

Returns: iterator(ranges::begin(base_), n_).

🔗

constexpr auto end() requires (!([simple-view](range.utility.helpers#concept:simple-view "25.5.2Helper concepts[range.utility.helpers]")<V> && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2Class template slide_­view[range.slide.view]")<const V>));

6

#

Returns:

If V models slide-caches-nothing,iterator(ranges::begin(base_) + range_difference_t(size()), n_)

Otherwise, if V models slide-caches-last,iterator(ranges::prev(ranges::end(base_), n_ - 1, ranges::begin(base_)), n_)

Otherwise, if V models common_range,iterator(ranges::end(base_), ranges::end(base_), n_)

Otherwise, sentinel(ranges::end(base_)).

7

#

Remarks: In order to provide the amortized constant-time complexity required by the range concept, this function caches the result within the slide_view for use on subsequent calls when V models slide-caches-last.

🔗

constexpr auto end() const requires [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2Class template slide_­view[range.slide.view]")<const V>;

8

#

Returns: begin() + range_difference_t(size()).

🔗

constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<V>; constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<const V>;

9

#

Effects: Equivalent to:auto sz = ranges::distance(base_) - n_ + 1;if (sz < 0) sz = 0;return to-unsigned-like(sz);

🔗

constexpr auto reserve_hint() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")<V>; constexpr auto reserve_hint() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")<const V>;

10

#

Effects: Equivalent to:auto sz = static_cast<range_difference_t<decltype((base_))>>(ranges::reserve_hint(base_)) -n_ + 1;if (sz < 0) sz = 0;return to-unsigned-like(sz);