• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <iterator>

    std::crbegin

    namespace std {
      template <class C>
      auto crbegin(const C& c) -> decltype(std::rbegin(c));
    }
    

    概要

    範囲の末尾を指す読み取り専用逆イテレータを取得する。

    戻り値

    #include <iostream>
    #include <vector>
    #include <iterator>
    #include <algorithm>
    
    void print(int x)
    {
      std::cout << x << " ";
    }
    
    int main()
    {
      // コンテナ
      {
        std::vector<int> v = {1, 2, 3};
    
        decltype(v)::const_reverse_iterator first = std::crbegin(v);
        decltype(v)::const_reverse_iterator last = std::crend(v);
    
        std::for_each(first, last, print);
      }
      std::cout << std::endl;
    
      // 組み込み配列
      {
        int ar[] = {4, 5, 6};
    
        std::reverse_iterator<const int*> first = std::crbegin(ar);
        std::reverse_iterator<const int*> last = std::crend(ar);
    
        std::for_each(first, last, print);
      }
      std::cout << std::endl;
    
      // 初期化子リスト
      {
        std::initializer_list<int> init = {7, 8, 9};
    
        std::reverse_iterator<const int*> first = std::crbegin(init);
        std::reverse_iterator<const int*> last = std::crend(init);
    
        std::for_each(first, last, print);
      }
    }
    

    出力

    3 2 1 
    6 5 4 
    9 8 7 
    

    バージョン

    言語

    • C++14

    処理系

    参照