• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <ranges>

    std::ranges::as_const_view::begin

    constexpr auto begin() requires (!simple-view<V>);      // (1)
    constexpr auto begin() const requires range<const V>;   // (2)
    

    概要

    viewの先頭要素を指すイテレータを取得する。

    戻り値

    入力viewV)のオブジェクトをbase_というメンバに保持するとして、(1)(2)どちらも

    return ranges::cbegin(base_);
    

    as_const_viewviews::as_constから生成している場合、ここで得られるイテレータは常にbasic_const_iteratorの特殊化となる。

    #include <ranges>
    #include <vector>
    #include <iostream>
    
    int main() {
      std::vector<int> vec = {1, 2, 3, 4, 5};
    
      std::ranges::as_const_view acv{vec};
    
      auto it = acv.begin();
    
      std::cout << *it << '\n';
    
      ++it;
      std::cout << *it << '\n';
    
      // 書き換え不可
      //*it = 0;
    }
    

    出力

    1
    2
    

    バージョン

    言語

    • C++23

    処理系

    参照