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::basic_const_iterator::base - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. iterator
  3. basic_const_iterator
  4. base

最終更新日時: 2024年06月11日 22時45分38秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<iterator>

std::basic_const_iterator::base(C++23)

constexpr const Iterator& base() const & noexcept;  // (1)
constexpr Iterator base() &&;  // (2)

概要

メンバ変数として保持している、元のイテレータを取得する。

戻り値

  • (1) : 元のイテレータへのconst参照を返す。
  • (2) : 元のイテレータをムーブして返す。

例

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

int main() {
  std::vector vec = {1, 2, 3, 4, 5};

  std::basic_const_iterator cit = vec.begin();

  std::cout << *cit << '\n';
  std::cout << *(cit.base()) << '\n';

  // 元のイテレータが可変イテレータならば要素を変更可能
  *(cit.base()) = 0;
  std::cout << *(cit.base()) << '\n';
}

出力

1
1
0

バージョン

言語

  • C++23

処理系

  • Clang: ??
  • GCC: 13.1 ✅
  • Visual C++: 2022 Update 6 ✅

参照

  • P2278R4 cbegin should always return a constant iterator
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.