最終更新日時(UTC):
が更新

履歴 編集

function
<iterator>

std::basic_const_iterator::operator->(C++23)

constexpr const auto* operator->() const
  requires is_lvalue_reference_v<iter_reference_t<Iterator>> &&
           same_as<remove_cvref_t<iter_reference_t<Iterator>>, value_type>;

概要

イテレータを通して参照先の要素のメンバにアクセスする

戻り値

ラップするイテレータをcurrent_というメンバに保持するとして

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

struct S {
  int n;

  void print() const {
    std::cout << "call const : " << this->n << '\n';
  }

  void print() {
    std::cout << "call non const : " << this->n << '\n';
  }
};

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

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

  cit->print();
}

出力

call const : 1

バージョン

言語

  • C++23

処理系

参照