• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <regex>

    std::regex_token_iterator::operator*

    const value_type& operator*() const;
    

    概要

    イテレータを間接参照する。

    要件

    シーケンスの終端を示すイテレータではない事。(シーケンス終端イテレータに対して呼び出した場合は未定義動作を引き起こす)

    戻り値

    *result(つまり、メンバ変数 result の参照先オブジェクト *result への const 参照)

    備考

    • value_typeregex_token_iterator のメンバ型で、sub_match<BidirectionalIterator> である。
    • 戻り値の型は const への参照であるため、この参照を通した変更はできない。
    • メンバ変数 result はあくまでも説明用のプライベートメンバ変数であるため、注意すること。

    #include <iostream>
    #include <iterator>
    #include <regex>
    #include <string>
    #include <initializer_list>
    
    int main()
    {
      const std::string s("enum E { enumerator1 = value1, enumerator2 = value2, enumerator3 = value3, };");
      const std::regex re(R"((\w+)\s*=\s*(\w+))");
    
      // 1 番目と 2 番目のサブマッチを順に繰り返す
      for (std::sregex_token_iterator it(std::begin(s), std::end(s), re, { 1, 2 }), end; it != end; ++it) {
        // 間接参照した結果を参照型のローカル変数 m に代入(m の型は const value_type&)
        auto&& m = *it;
        std::cout << "match range = (" << m.first - std::begin(s) << ", " << m.second - std::begin(s) << "), "
                     "str = '" << m.str() << '\'' << std::endl;
      }
    }
    

    出力

    match range = (9, 20), str = 'enumerator1'
    match range = (23, 29), str = 'value1'
    match range = (31, 42), str = 'enumerator2'
    match range = (45, 51), str = 'value2'
    match range = (53, 64), str = 'enumerator3'
    match range = (67, 73), str = 'value3'
    

    バージョン

    言語

    • C++11

    処理系

    • Clang: 3.0 , 3.1 , 3.2 , 3.3 , 3.4 , 3.5 , 3.6
    • GCC: 4.9.0 , 4.9.1 , 5.0.0
    • ICC: ??
    • Visual C++: ??

    関連項目

    名前 説明 対応バージョン
    operator-> メンバアクセス C++11
    (constructor) コンストラクタ C++11
    operator++ インクリメント C++11
    operator== 等値比較 C++11