title | description | ms.date | f1_keywords | helpviewer_keywords | dev_langs | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
drop_view class (C++ Standard Library) |
API reference for the Standard Template Library (STL) <ranges> drop_view class, which creates a view from another view, skipping the first count elements. |
10/19/2022 |
|
|
|
Create a view that excludes the first N elements of a range.
template<ranges::view V>
class drop_view : public ranges::view_interface<drop_view<V>>;
V
The type of the underlying view.
For a description of the following entries, see View class characteristics
Characteristic | Description |
---|---|
Range adaptor | views::drop |
Underlying range | Must satisfy output_range or higher |
Element type | Same as the underlying range |
View iterator category | Same as the underlying range |
Sized | Only if the underlying range satisfies sized_range |
Is const -iterable |
Only if the underlying range is const iterable and satisfies random_access_range and sized_range |
Common range | Only if the underlying range is a common_range |
Borrowed range | Only if the underlying range satisfies borrowed_range |
Member functions | Description |
---|---|
ConstructorsC++20 | Construct a drop_view . |
base C++20 |
Get the underlying view. |
begin C++20 |
Get an iterator to the first element. |
end C++20 |
Get the sentinel at the end of the view. |
size C++20 |
Get the number of elements in this view. The underlying range must satisfy sized_range . |
Inherited from view_interface |
Description |
back C++20 |
Get the last element. |
data C++20 |
Get a pointer to the first element. |
empty C++20 |
Test whether the drop_view is empty. |
front C++20 |
Get the first element. |
operator[] C++20 |
Get the element at the specified position. |
operator bool C++20 |
Test whether the drop_view isn't empty. |
Header: <ranges>
(since C++20)
Namespace: std::ranges
Compiler Option: /std:c++20
or later is required.
Construct an instance of a drop_view
template<ranges::view V>
class drop_view : public ranges::view_interface<drop_view<V>>
V
The type of the underlying view.
A view of the underlying range, excluding the specified number of elements from the front.
If you specify more elements to drop than exist in the underlying range, then an empty_view
is returned.
The best way to create a drop_view
is by using the views::drop
range adaptor. Range adaptors are the intended way to create view classes. The view types are exposed in case you want to create your own custom view type.
// requires /std:c++20 or later
#include <ranges>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v{ 1, 2, 3, 4, 5 };
auto newView = std::views::drop(v, 3);
for (auto e : newView) // outputs 4 5
{
std::cout << e << ' ';
}
std::cout << '\n';
auto numbers = std::views::iota(0) | std::views::take(10); // generate a view of 10 integers
for (auto i : numbers | std::views::drop(5)) // use the '|' syntax to create a drop_view
{
std::cout << i << ' '; // outputs 5 6 7 8 9
}
}
4 5
5 6 7 8 9
Gets a copy of the underlying view.
// Uses a copy constructor to return the underlying view
constexpr V base() const& requires std::copy_constructible<V>;
// Uses a move constructor to return the underlying view
constexpr V base() &&;
None.
The underlying view.
Get an iterator to the first element in the drop_view
.
constexpr auto begin()
requires (!(Simple_view<V> && ranges::random_access_range<const V> && ranges::sized_range<const V>));
constexpr auto begin() const
requires ranges::random_access_range<const V> && ranges::sized_range<const V>;
None.
An iterator pointing at the first element in the drop_view
.
:::image type="content" source="media/begin-end-sentinel.png" alt-text="Picture of a vector with the elements 10, 20, and 30. The first element contains 10 and is labeled begin(). The last element contains 30 and is labeled 'last element'. An imaginary box after the last element indicates the sentinel and is labeled end().":::
Get the sentinel at the end of the drop_view
constexpr auto end() requires (!Simple_view<V>);
constexpr auto end() const requires ranges::range<const V>;
None.
The sentinel that follows the last element in the drop_view
:
:::image type="content" source="media/begin-end-sentinel.png" alt-text="Picture of a vector with the elements 10, 20, and 30. The first element contains 10 and is labeled begin(). The last element contains 30 and is labeled 'last element'. An imaginary box after the last element indicates the sentinel and is labeled end().":::
Get the number of elements in the drop_view
.
constexpr auto size() requires ranges::sized_range<V>;
constexpr auto size() const requires ranges::sized_range<const V>;
None.
The number of elements in the drop_view
.
The underlying range must satisfy sized_range
.
<ranges>
drop
range adaptor
take_while()
take_while_view
View classes