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

履歴 編集

function template
<regex>

std::swap (非メンバ関数)(C++11)

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

概要

2 つの match_results オブジェクトの内容を交換する。

効果

m1.swap(m2)

#include <iostream>
#include <regex>

int main()
{
  const char s[] = "abc 012 def";

  const std::regex re1(R"((\w+) (\d+))");
  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"((\d+) (\w+))");
  std::cmatch m2;
  std::regex_search(s, m2, re2);
  for (auto&& sub : m2) {
    std::cout << sub << std::endl;
  }
  std::cout << std::endl;

  std::swap(m1, m2);

  for (auto&& sub : m1) {
    std::cout << sub << std::endl;
  }
  std::cout << std::endl;
  for (auto&& sub : m2) {
    std::cout << sub << std::endl;
  }
}

出力

abc 012
abc
012

012 def
012
def

012 def
012
def

abc 012
abc
012

バージョン

言語

  • C++11

処理系