<regex>
Operadores
operator!=
operator>
operator>=
operator<
operator<<
operator<=
operator==
operator!=
Comparación de desigualdad para varios objetos.
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator!=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator!=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator!=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator!=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
template <class BidIt, class Alloc>
bool operator!=(const match_results<BidIt, Alloc>& left,
const match_results<BidIt, Alloc>& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de la plantilla devuelve !(left == right)
.
Ejemplo
// std__regex__operator_ne.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "match == " << mr.str() << std::endl;
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "match != match == " << std::boolalpha
<< (mr != mr) << std::endl;
std::cout << "sub != sub == " << std::boolalpha
<< (sub != sub) << std::endl;
std::cout << "string(\"aab\") != sub == " << std::boolalpha
<< (Mystr("aab") != sub) << std::endl;
std::cout << "sub != string(\"aab\") == " << std::boolalpha
<< (sub != Mystr("aab")) << std::endl;
std::cout << "\"aab\" != sub == " << std::boolalpha
<< ("aab" != sub) << std::endl;
std::cout << "sub != \"aab\" == " << std::boolalpha
<< (sub != "aab") << std::endl;
std::cout << "'a' != sub == " << std::boolalpha
<< ('a' != sub) << std::endl;
std::cout << "sub != 'a' == " << std::boolalpha
<< (sub != 'a') << std::endl;
return (0);
}
match == caaa
sub == aaa
match != match == false
sub != sub == false
string("aab") != sub == true
sub != string("aab") == true
"aab" != sub == true
sub != "aab" == true
'a' != sub == true
sub != 'a' == true
operator<
Comparación menor que para varios objetos.
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator<(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator<(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de plantilla convierte sus argumentos a un tipo de cadena y devuelve true solo si el valor convertido de left se compara menos que el valor convertido de right.
Ejemplo
// std__regex__operator_lt.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub < sub == " << std::boolalpha
<< (sub < sub) << std::endl;
std::cout << "string(\"aab\") < sub == " << std::boolalpha
<< (Mystr("aab") < sub) << std::endl;
std::cout << "sub < string(\"aab\") == " << std::boolalpha
<< (sub < Mystr("aab")) << std::endl;
std::cout << "\"aab\" < sub == " << std::boolalpha
<< ("aab" < sub) << std::endl;
std::cout << "sub < \"aab\" == " << std::boolalpha
<< (sub < "aab") << std::endl;
std::cout << "'a' < sub == " << std::boolalpha
<< ('a' < sub) << std::endl;
std::cout << "sub < 'a' == " << std::boolalpha
<< (sub < 'a') << std::endl;
return (0);
}
sub == aaa
sub < sub == false
string("aab") < sub == false
sub < string("aab") == true
"aab" < sub == false
sub < "aab" == true
'a' < sub == true
sub < 'a' == false
operator<<
Inserta un sub_match en una secuencia.
template <class Elem, class IOtraits, class Alloc, class BidIt>
basic_ostream<Elem, IOtraits>& operator<<(basic_ostream<Elem, IOtraits>& os,
const sub_match<BidIt>& right);
Parámetros
Elem
El tipo de elemento.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
BidIt
Tipo de iterador.
os
Secuencia de salida.
right
Objeto que se va a insertar.
Comentarios
El operador de la plantilla devuelve os << right.str()
.
Ejemplo
// std__regex__operator_ins.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[0];
std::cout << "whole match: " << sub << std::endl;
return (0);
}
whole match: caaa
operator<=
Comparación menor o igual que para varios objetos.
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator<=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator<=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de la plantilla devuelve !(right < left)
.
Ejemplo
// std__regex__operator_le.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub <= sub == " << std::boolalpha
<< (sub <= sub) << std::endl;
std::cout << "string(\"aab\") <= sub == " << std::boolalpha
<< (Mystr("aab") <= sub) << std::endl;
std::cout << "sub <= string(\"aab\") == " << std::boolalpha
<< (sub <= Mystr("aab")) << std::endl;
std::cout << "\"aab\" <= sub == " << std::boolalpha
<< ("aab" <= sub) << std::endl;
std::cout << "sub <= \"aab\" == " << std::boolalpha
<< (sub <= "aab") << std::endl;
std::cout << "'a' <= sub == " << std::boolalpha
<< ('a' <= sub) << std::endl;
std::cout << "sub <= 'a' == " << std::boolalpha
<< (sub <= 'a') << std::endl;
return (0);
}
sub == aaa
sub <= sub == true
string("aab") <= sub == false
sub <= string("aab") == true
"aab" <= sub == false
sub <= "aab" == true
'a' <= sub == true
sub <= 'a' == false
operator==
Comparación de igualdad para varios objetos.
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator==(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator==(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type* left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type* right);
template <class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
template <class BidIt, class Alloc>
bool operator==(const match_results<BidIt, Alloc>& left,
const match_results<BidIt, Alloc>& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de la plantilla convierte cada uno de sus argumentos a un tipo de cadena y devuelve el resultado de realizar una comparación de igualdad de los objetos convertidos.
Cuando un operador de plantilla convierte sus argumentos a un tipo de cadena, usa la primera de las siguientes transformaciones que se aplica:
los argumentos cuyos tipos sean una especialización de la plantilla de clase match_results
o sub_match
se convierten mediante una llamada a la función miembro str
;
los argumentos cuyos tipos sean una especialización de la plantilla de clase basic_string
no se cambian;
todos los demás tipos de argumento se convierten pasando el valor del argumento al constructor para una especialización adecuada de la plantilla de clase basic_string
.
Ejemplo
// std__regex__operator_eq.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "match == " << mr.str() << std::endl;
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "match == match == " << std::boolalpha
<< (mr == mr) << std::endl;
std::cout << "sub == sub == " << std::boolalpha
<< (sub == sub) << std::endl;
std::cout << "string(\"aab\") == sub == " << std::boolalpha
<< (Mystr("aab") == sub) << std::endl;
std::cout << "sub == string(\"aab\") == " << std::boolalpha
<< (sub == Mystr("aab")) << std::endl;
std::cout << "\"aab\" == sub == " << std::boolalpha
<< ("aab" == sub) << std::endl;
std::cout << "sub == \"aab\" == " << std::boolalpha
<< (sub == "aab") << std::endl;
std::cout << "'a' == sub == " << std::boolalpha
<< ('a' == sub) << std::endl;
std::cout << "sub == 'a' == " << std::boolalpha
<< (sub == 'a') << std::endl;
return (0);
}
match == caaa
sub == aaa
match == match == true
sub == sub == true
string("aab") == sub == false
sub == string("aab") == false
"aab" == sub == false
sub == "aab" == false
'a' == sub == false
sub == 'a' == false
operator>
Comparación mayor que para varios objetos.
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator>(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator>(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de la plantilla devuelve right < left
.
Ejemplo
// std__regex__operator_gt.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub > sub == " << std::boolalpha
<< (sub > sub) << std::endl;
std::cout << "string(\"aab\") > sub == " << std::boolalpha
<< (Mystr("aab") > sub) << std::endl;
std::cout << "sub > string(\"aab\") == " << std::boolalpha
<< (sub > Mystr("aab")) << std::endl;
std::cout << "\"aab\" > sub == " << std::boolalpha
<< ("aab" > sub) << std::endl;
std::cout << "sub > \"aab\" == " << std::boolalpha
<< (sub > "aab") << std::endl;
std::cout << "'a' > sub == " << std::boolalpha
<< ('a' > sub) << std::endl;
std::cout << "sub > 'a' == " << std::boolalpha
<< (sub > 'a') << std::endl;
return (0);
}
sub == aaa
sub > sub == false
string("aab") > sub == true
sub > string("aab") == false
"aab" > sub == true
sub > "aab" == false
'a' > sub == false
sub > 'a' == true
operator>=
Comparación mayor o igual que para varios objetos.
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator>=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator>=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
Parámetros
BidIt
Tipo de iterador.
IOtraits
La clase de características de cadena.
Alloc
Clase de asignador.
left
El objeto izquierdo que se compara.
right
El objeto derecho que se compara.
Comentarios
Cada operador de la plantilla devuelve !(left < right)
.
Ejemplo
// std__regex__operator_ge.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub >= sub == " << std::boolalpha
<< (sub >= sub) << std::endl;
std::cout << "string(\"aab\") >= sub == " << std::boolalpha
<< (Mystr("aab") >= sub) << std::endl;
std::cout << "sub >= string(\"aab\") == " << std::boolalpha
<< (sub >= Mystr("aab")) << std::endl;
std::cout << "\"aab\" >= sub == " << std::boolalpha
<< ("aab" >= sub) << std::endl;
std::cout << "sub >= \"aab\" == " << std::boolalpha
<< (sub >= "aab") << std::endl;
std::cout << "'a' >= sub == " << std::boolalpha
<< ('a' >= sub) << std::endl;
std::cout << "sub >= 'a' == " << std::boolalpha
<< (sub >= 'a') << std::endl;
return (0);
}
sub == aaa
sub >= sub == true
string("aab") >= sub == true
sub >= string("aab") == false
"aab" >= sub == true
sub >= "aab" == false
'a' >= sub == false
sub >= 'a' == true
Vea también
<regex>
regex_constants (Clase)
regex_error (Clase)
<regex> functions
regex_iterator (Clase)
regex_token_iterator (Clase)
regex_traits (Clase)
<regex> typedefs