• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <regex>

    std::regex_token_iterator::operator!=

    // operator==により、以下の演算子が使用可能になる (C++20)
    bool operator!=(const regex_token_iterator& right) const;
    

    概要

    regex_token_iterator の非等値比較を行う。

    戻り値

    !(*this == right)

    備考

    • 本メンバ関数が true を返したとしても、イテレータの指す文字列が等しくないとは限らないことに注意すること。(下記の例を参照)

    #include <iostream>
    #include <iterator>
    #include <regex>
    #include <string>
    #include <initializer_list>
    
    int main()
    {
      // 検索対象は 1 番目の列挙子と 2 番目の列挙子が同じ文字列になっている
      const std::string s("enum E { enumerator1 = value1, enumerator1 = value1, enumerator3 = value3, };");
      const std::regex re(R"((\w+)\s*=\s*(\w+))"); // 列挙子とその値をグループ化
    
      // 同一の引数で 2 つのイテレータを構築する
      std::sregex_token_iterator it1(std::begin(s), std::end(s), re, { 1, 2 });
      std::sregex_token_iterator it2(std::begin(s), std::end(s), re, { 1, 2 });
    
      std::advance(it2, 2); // 2 つ進める(2 番目の enumerator1 を指す)
    
      // operator!= で比較する
      std::cout << std::boolalpha << (it1 != it2) << std::endl;
    
      // 参考のため、各サブマッチの詳細を出力する
      std::cout << "match range = (" << (it1->first - std::begin(s)) << ", " << (it1->second - std::begin(s)) << "), "
                   "str = '" << it1->str() << '\'' << std::endl;
      std::cout << "match range = (" << (it2->first - std::begin(s)) << ", " << (it2->second - std::begin(s)) << "), "
                   "str = '" << it2->str() << '\'' << std::endl;
    }
    

    出力

    true
    match range = (9, 20), str = 'enumerator1'
    match range = (31, 42), str = 'enumerator1'
    

    バージョン

    言語

    • 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
    operator-> メンバアクセス C++11
    (constructor) コンストラクタ C++11
    operator++ インクリメント C++11
    operator== 等値比較 C++11

    参照