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

  1. リファレンス
  2. iterator
  3. make_const_iterator

最終更新日時: 2025年07月09日 00時33分39秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<iterator>

std::make_const_iterator(C++23)

namespace std {
  template<input_iterator I>
  constexpr const_iterator<I> make_const_iterator(I it);
}

概要

basic_const_iteratorのヘルパ関数。

戻り値

return it;

戻り値型は必ずしもbasic_const_iteratorの特殊化になるわけではない。

例

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

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

  auto cit = std::make_const_iterator(vec.begin());
  auto cse = std::make_const_sentinel(vec.end());

  for (auto& n : std::ranges::subrange{cit, cse}) {
    std::cout << n << ", ";
    // 変更できない
    // n = 0;
  }
}

出力

1, 2, 3, 4, 5, 

バージョン

言語

  • 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.