GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::reverse_iterator::operator[] - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. iterator
  3. reverse_iterator
  4. operator[]

最終更新日時: 2026年08月27日 11時21分44秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<iterator>

std::reverse_iterator::operator[]

unspecified operator[](difference_type n) const;           // (1) C++98
constexpr unspecified operator[](difference_type n) const; // (1) C++17

概要

任意の位置にランダムアクセスする。

戻り値

current[-n-1]

例

#include <iostream>
#include <vector>
#include <iterator>

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

  std::reverse_iterator<decltype(v)::iterator> it(v.end());

  int& result = it[1]; // 1番目の要素にランダムアクセス

  std::cout << result << std::endl;
}

出力

2

参照

  • P0031R0 A Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range Access
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.