Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::view_interface<D>::operator[]

      From cppreference.com
      <cpp‎ |ranges‎ |view interface
       
       
      Ranges library
      Range adaptors
       
       
      template<ranges::random_access_range R= D>
      constexpr decltype(auto) operator[](ranges::range_difference_t<R> n);
      (1)(since C++20)
      template<ranges::random_access_range R=const D>
      constexpr decltype(auto) operator[](ranges::range_difference_t<R> n)const;
      (2)(since C++20)

      The default implementation ofoperator[] member function obtains the element at the specified offset relative to the beginning iterator, reusing theoperator[] of the iterator type.

      1) Letderived bestatic_cast<D&>(*this). Equivalent toreturnranges::begin(derived)[n];.
      2) Same as(1), except thatderived isstatic_cast<const D&>(*this).

      Contents

      [edit]Parameters

      n - position of the element to return

      [edit]Return value

      The element at offsetn relative to the beginning iterator.

      [edit]Notes

      In C++20, no type derived fromstd::ranges::view_interface in the standard library provides their ownoperator[] member function.

      However, following derived types cannot use the default implementations, as they never satisfyrandom_access_range:

      The inheritedoperator[] member function is available forstd::ranges::empty_view, but a call to it always results in undefined behavior.

      [edit]Example

      This section is incomplete
      Reason: no example
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view_interface/operator_at&oldid=137471"

      [8]ページ先頭

      ©2009-2025 Movatter.jp