Namespaces
Variants

std::ranges::as_input_view<V>::iterator

From cppreference.com
 
 
Ranges library
Range adaptors
 
 
template< bool Const >
struct /*iterator*/;
(since C++26)
(exposition only*)

ranges::as_input_view<V>::iterator is the type of the iterators returned by begin() of ranges::as_input_view<V>.

The type /*iterator*/<true> is returned by the const-qualified overloads. The type /*iterator*/<false> is returned by the non-const-qualified overloads.

iterator is an input_iterator, but does not satisfy LegacyInputIterator, and thus does not work with pre-C++20 algorithms.

Nested types

Exposition-only types
Type Definition
Base maybe-const <Const, V>
(exposition-only member type*)
Iterator property types
Type Definition
difference_type ranges::range_difference_t<Base>
value_type ranges::range_value_t<Base>
iterator_concept std::input_iterator_tag

Data members

Member Description
ranges::iterator_t<Base> current_ an iterator into the underlying view
(exposition-only member object*)

Member functions

constructs the iterator
(public member function)
returns the underlying iterator
(public member function)
move-assigns the stored iterator
(public member function)
forwards to the underlying iterator
(public member function)
advances the iterator
(public member function)

std::ranges::as_input_view::iterator::iterator

/*iterator*/()
    requires std::default_initializable<ranges::iterator_t<Base>> = default;
(1) (since C++26)
/*iterator*/( /*iterator*/&& ) = default;
(2) (since C++26)
constexpr /*iterator*/( /*iterator*/<!Const> i )
    requires Const && std::convertible_to<ranges::iterator_t<V>,
                                          ranges::iterator_t<Base>>;
(3) (since C++26)
constexpr explicit /*iterator*/( ranges::iterator_t<Base> current );
(4) (since C++26)
(exposition only*)
1) The default constructor is defaulted.
2) The move constructor is defaulted.
3) Initializes current_ with std::move(i./*current_*/).
4) Initializes current_ with std::move(current). This constructor is inaccessible to the users.

std::ranges::as_input_view::iterator::base

constexpr ranges::iterator_t<Base> base() &&;
(1) (since C++26)
constexpr const ranges::iterator_t<Base>& base() const & noexcept;
(2) (since C++26)
1) Returns std::move(/*current_*/).
2) Returns current_.

std::ranges::as_input_view::iterator::operator=

/*iterator*/& operator=( /*iterator*/&& ) = default;
(since C++26)

The move assignment operator is defaulted.

std::ranges::as_input_view::iterator::operator*

constexpr decltype(auto) operator*() const;
(since C++26)

Returns *current_.

std::ranges::as_input_view::iterator::operator++

constexpr /*iterator*/& operator++();
(1) (since C++26)
constexpr void operator++( int );
(2) (since C++26)
1) Equivalent to ++/*current_*/; return *this;.
2) Equivalent to ++*this.

Non-member functions

compares the underlying iterator and ranges::sentinel_t<Base>
(function)
(C++26)
computes the distance between a sentinel and an iterator returned from ranges::as_input_view::begin()
(function)
(C++26)
casts the result of dereferencing the underlying iterator to its associated rvalue reference type
(function)
(C++26)
swaps the objects pointed to by two underlying iterators
(function)

operator==(std::ranges::as_input_view::iterator)

friend constexpr bool operator==( const /*iterator*/& x,
                                  const ranges::sentinel_t<Base>& y );
(since C++26)

Equivalent to return x./*current_*/ == y;.

The != operator is synthesized from operator==.

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::as_input_view::iterator is an associated class of the arguments.

operator-(std::ranges::as_input_view::iterator)

friend constexpr difference_type operator-( const ranges::sentinel_t<Base>& y,
                                            const /*iterator*/& x )
    requires std::sized_sentinel_for<ranges::sentinel_t<Base>,
                                     ranges::iterator_t<Base>>;
(1) (since C++26)
friend constexpr difference_type operator-( const /*iterator*/& x,
                                            const ranges::sentinel_t<Base>& y )
    requires std::sized_sentinel_for<ranges::sentinel_t<Base>,
                                     ranges::iterator_t<Base>>;
(2) (since C++26)
1) Equivalent to returns y - x./*current_*/;
2) Equivalent to returns x./*current_*/ - y;

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::as_input_view::iterator is an associated class of the arguments.

iter_move(std::ranges::as_input_view::iterator)

friend constexpr ranges::range_rvalue_reference_t<Base>
    iter_move( const /*iterator*/& i )
        noexcept(noexcept(ranges::iter_move(i./*current_*/)));
(since C++26)

Equivalent to return ranges::iter_move(i./*current_*/);.

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::as_input_view::iterator is an associated class of the arguments.

iter_swap(std::ranges::as_input_view::iterator)

friend constexpr void iter_swap( const /*iterator*/& x, const /*iterator*/& y )
    noexcept(noexcept(ranges::iter_swap(x./*current_*/, y./*current_*/)))
        requires std::indirectly_swappable<ranges::iterator_t<Base>>;
(since C++26)

Equivalent to ranges::iter_swap(x./*current_*/, y./*current_*/).

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::as_input_view::iterator is an associated class of the arguments.

Example

#include <array>
#include <concepts>
#include <iostream>
#include <ranges>
#include <vector>

int main()
{
    auto matrix = std::vector<std::vector<int>>{{1, 2}, {3, 4}};

    auto standard_pipeline = matrix
                           | std::views::join
                           ;
    using StandardIterator = std::ranges::iterator_t<decltype(standard_pipeline)>;
    static_assert(std::forward_iterator<StandardIterator>,
                  "Standard pipeline results in a forward iterator.");

    auto optimized_pipeline = matrix
                            | std::views::as_input
                            | std::views::join
                            ;
    using OptimizedIterator = std::ranges::iterator_t<decltype(optimized_pipeline)>;
    static_assert(std::input_iterator<OptimizedIterator>,
                  "Optimized pipeline results in an input iterator.");
    static_assert(!std::forward_iterator<OptimizedIterator>,
                  "Success! The pipeline stripped away forward iterator capabilities.");

    auto vec = std::vector{1, 2};
    auto arr = std::array{3, 4};

    auto normal_concat = std::views::concat(vec, arr);
    static_assert(std::ranges::random_access_range<decltype(normal_concat)>,
                  "concat preserves random access if all inputs support it");

    // Concat with as_input downgrades the entire pipeline to an Input Range
    auto single_pass_concat = std::views::concat(vec | std::views::as_input, arr);
    static_assert(std::ranges::input_range<decltype(single_pass_concat)>);
    static_assert(!std::ranges::forward_range<decltype(single_pass_concat)>);
}