Programming/c++

[c++] regex swap 함수

owls 2023. 1. 20. 14:07
728x90

1.함수 헤더 파일

#include <regex>

2.함수 원형

template <class Elem, class RXtraits>
void swap(
    basic_regex<Elem, RXtraits, Alloc>& left,
    basic_regex<Elem, RXtraits>& right) noexcept;

template <class Elem, class IOtraits, class BidIt, class Alloc>
void swap(
    match_results<BidIt, Alloc>& left,
    match_results<BidIt, Alloc>& right) noexcept;

 

3. Parameter

Elem The type of element to find a match for.
RXtraits The attribute class for the element.

 

 

4. Described

템플릿 함수는 일정한 시간 내에 인수의 내용을 교환하고 예외를 발생시키지 않습니다.

 

4.예제

#include <regex>
#include <iostream>

int main()
{
	regex rx0("c(a*)|(b)");
    regex rx1;
    cmatch mr0;
    cmatch mr1;

    swap(rx0, rx1);
    regex_search("xcaaay", mr1, rx1);
    swap(mr0, mr1);

    csub_match sub = mr0[1];
    cout << "matched == " << boolalpha << sub.matched << endl;
    cout << "length == " << sub.length() << endl;
    cout << "string == " << sub << endl;
}

 

728x90