Section hub

std::ranges::views::drop, std::ranges::drop_view

  1. A range adaptor consisting of elements of the underlying sequence, skipping the first N elements.

# Declarations

template< ranges::view V >
class drop_view
: public ranges::view_interface<drop_view<V>>

(since C++20)

namespace views {
inline constexpr /* unspecified */ drop = /* unspecified */;
}

(since C++20)

Call signature
template< ranges::viewable_range R >
requires /* see below */
constexpr ranges::view auto
drop( R&& r, ranges::range_difference_t<R> count );

(since C++20)

template< class DifferenceType >
constexpr /* range adaptor closure */ drop( DifferenceType&& count );

(since C++20)

# Example

#include <iostream>
#include <ranges>
 
int main()
{
    const auto nums = {1, 2, 3, 4, 5, 6, 7};
 
    std::cout << "drop " << 2 << ": ";
    for (int i : std::ranges::drop_view{nums, 2})
        std::cout << i << ' ';
    std::cout << '\n';
 
    std::cout << "drop " << 3 << ": ";
    for (int i : nums | std::views::drop(3))
        std::cout << i << ' ';
    std::cout << '\n';
 
    std::cout << "drop " << 4 << ": ";
    for (int i : std::views::iota(1, 8) | std::views::drop(4))
        std::cout << i << ' ';
    std::cout << '\n';
 
    // Note that dropping more than the number of elements is OK:
    for (int dp : {5, 6, 7, 890, 100500})
    {
        std::cout << "drop " << dp << ": ";
        for (int i : std::views::iota(1, 8) | std::views::drop(dp))
            std::cout << i << ' ';
        std::cout << '\n';
    }
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3407C++20views::drop sometimes fails toconstruct a sized random access rangethe construction is adjustedso that it is always valid
LWG 3494C++20drop_view was never a borrowed_rangeit is a borrowed_range if its underlying view is

# See also

This hub groups the ranges library by user task rather than by raw reference tree shape. View types and adaptor objects are presented as the same conceptual item.

Core adapters

Start here for the adapters most people reach for first when building pipelines.

Utility views

These adapt shape, ownership, or projection rather than representing the “headline” pipeline steps.

New in C++23 / C++26

Newer adapters, kept as a compact scan list with only standard badges.

All entities by category

A lighter-weight index of the full ranges surface, grouped by conceptual task instead of raw page-tree names.

74 entities