• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <regex>

    std::match_results::operator==

    namespace std {
      template <class BidirectinalIterator, class Allocator>
      bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
                      const match_results<BidirectionalIterator, Allocator>& m2);
    }
    

    概要

    match_results オブジェクトを等値比較する。

    戻り値

    • どちらも ready() == false である場合、true を返す。
    • いずれかが ready() == true で、もう一方が ready() == false である場合、false を返す。
    • どちらも ready() == true である場合、以下のいずれかの条件を満たす場合に限り true を返す。

    備考

    本関数では、基本的に文字列としての比較しかしていないため、実際には等しくない場合でも等しいと判断される場合がある。

    #include <iostream>
    #include <regex>
    
    int main()
    {
      const char s[] = "abc 012 def";
    
      const std::regex re1(R"((\w+)\s+(\d+)\s+(\w+))");
      std::cmatch m1;
      std::regex_search(s, m1, re1);
      for (auto&& sub : m1) {
        std::cout << sub << std::endl;
      }
      std::cout << std::endl;
    
      const std::regex re2(R"((\w*) (\w*) (\w*))");
      std::cmatch m2;
      std::regex_search(s, m2, re2);
      for (auto&& sub : m2) {
        std::cout << sub << std::endl;
      }
      std::cout << std::endl;
    
      std::cout << std::boolalpha << (m1 == m2) << std::endl;
    }
    

    出力

    abc 012 def
    abc
    012
    def
    
    abc 012 def
    abc
    012
    def
    
    true
    

    バージョン

    言語

    • 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++: ??