Comparison operators — cppreference.com
<metanoindex/>
Compare les arguments .
Original:
Compares the arguments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
| Operator name | Syntax | Overloadable | Prototype examples (for class T)
| |
|---|---|---|---|---|
| Inside class definition | Outside class definition | |||
| equal to | a == b
|
Yes | bool T::operator ==(const T2 &b) const;
|
bool operator ==(const T &a, const T2 &b);
|
| not equal to | a != b
|
Yes | bool T::operator !=(const T2 &b) const;
|
bool operator !=(const T &a, const T2 &b);
|
| less than | a < b
|
Yes | bool T::operator <(const T2 &b) const;
|
bool operator <(const T &a, const T2 &b);
|
| greater than | a > b
|
Yes | bool T::operator >(const T2 &b) const;
|
bool operator >(const T &a, const T2 &b);
|
| less than or equal to | a <= b
|
Yes | bool T::operator <=(const T2 &b) const;
|
bool operator <=(const T &a, const T2 &b);
|
| greater than or equal to | a >= b
|
Yes | bool T::operator >=(const T2 &b) const;
|
bool operator >=(const T &a, const T2 &b);
|
| ||||
Explication
Retourne le résultat booléen de la comparaison des valeurs des arguments qui ne sont pas modifiés .
Original:
Returns the boolean result of comparison of the values of the arguments, which are not modified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Opérateurs arithmétiques
Pour chaque paire de types arithmétiques promus L et R, y compris les types d'énumération, les signatures de fonction suivants participent à la résolution de surcharge:
Original:
For every pair of promoted arithmetic types L and R, including enumeration types, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
<tbody> </tbody>
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Si les opérandes a arithmétique ou une énumération de type (scope ou sans portée), les conversions arithmétiques usuelles' sont effectués suivant les règles de opérateurs arithmétiques. Les valeurs sont comparées après conversion:
Original:
If the operands has arithmetic or enumeration type (scoped or unscoped), usual arithmetic conversions are performed following the rules for opérateurs arithmétiques. The values are compared after conversions:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#include <iostream> int main() { std::cout << std::boolalpha; int n = -1; int n2 = 1; std::cout << " -1 == 1? " << (n == n2) << '\n' << "Comparing two signed values:\n" << " -1 < 1? " << (n < n2) << '\n' << " -1 > 1? " << (n > n2) << '\n'; unsigned int u = 1; std::cout << "Comparing signed and unsigned:\n" << " -1 < 1? " << (n < u) << '\n' << " -1 > 1? " << (n > u) << '\n'; unsigned char uc = 1; std::cout << "Comparing signed and smaller unsigned:\n" << " -1 < 1? " << (n < uc) << '\n' << " -1 > 1? " << (n > uc) << '\n'; }
Résultat :
-1 == 1? false Comparing two signed values: -1 < 1? true -1 > 1? false Comparing signed and unsigned: -1 < 1? false -1 > 1? true Comparing signed and smaller unsigned: -1 < 1? true -1 > 1? false
Les opérateurs de comparaison de pointeurs
Pour chaque type de P qui est soit pointeur à l'objet ou au pointeur de fonction ou std::nullptr_t, et pour chaque type de MP qui est un pointeur vers l'objet membre ou un pointeur vers une fonction membre, les signatures de fonction suivants participent à la résolution de surcharge:
Original:
For every type P which is either pointer to object or pointer to function or std::nullptr_t, and for every type MP that is a pointer to member object or pointer to member function, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
<tbody> </tbody>
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Les opérateurs de comparaison peuvent être utilisés pour comparer deux pointeurs (ou pointeurs-vers-membres, pour operator== et operator!= uniquement) ou un pointeur et un pointeur NULL constante, ou deux constantes pointeur nul (mais seulement dans la mesure où au moins l'un d'entre eux est std::nullptr_t: comparaison de NULL et NULL suit des règles arithmétiques). Conversions de pointeurs (pointeur vers conversions membres si les arguments sont des pointeurs vers des membres) et conversions de qualification sont appliquées aux deux opérandes afin d'obtenir l composite de type pointeur, comme suit
Original:
Comparison operators can be used to compare two pointers (or pointers-to-members, for operator== and operator!= only), or a pointer and a null pointer constant, or two null pointer constants (but only as long as at least one of them is std::nullptr_t: comparison of NULL and NULL follows arithmetic comparison rules). Conversions de pointeurs (pointer to member conversions if the arguments are pointers to members) and conversions de qualification are applied to both operands to obtain the composite pointer type, as follows
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
Si les deux opérandes sont des constantes pointeur NULL, le type de pointeur composite est std::nullptr_t
Original:
If both operands are null pointer constants, the composite pointer type is std::nullptr_t
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Si une opérande d'une constante de pointeur nul et l'autre est un pointeur, du type composite, c'est exactement le type de pointeur
Original:
If one operand a null pointer constant and the other is a pointer, the composite type is exactly the pointer type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
Si les deux opérandes sont des pointeurs vers le même type, avec différents cv-qualification, le composite est un pointeur vers le même type de cv-qualification qui est une union de la CV-qualification des arguments .
Original:
If both operands are pointers to the same type, with different cv-qualification, the composite is pointer to the same type with cv-qualification that is a union of the cv-qualifications of the arguments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Notez que cela implique que n'importe quel pointeur peut être comparé à void* .
Original:
Note that this implies that any pointer can be compared with void*.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Les résultats de la comparaison de deux pointeurs (après conversion) sont déterminés comme suit:
Original:
Results of comparing two pointers (after conversions) are determined as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
Si les pointeurs p et q
Original:
If the pointers p and q
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
a)
pointer vers le même objet ou d'une fonction
Original:
point to the same object or function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
b)
ou pointer un après la fin de la même matrice
Original:
or point one past the end of the same array
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
c)
ou sont tous les deux pointeurs nuls
Original:
or are both null pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alors les pointeurs' sont égales: p==q, p<=q et p>=q retour true, tandis que p!=q, p<q et p>q retour false,
Original:
then the pointers compare equal: p==q, p<=q, and p>=q return true, while p!=q, p<q, and p>q return false,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Si l'un des opérandes est un pointeur nul et l'autre non, ils comparent inégale: p==q retours true, p!=q retours false, le comportement des autres opérateurs n'est pas spécifié .
Original:
If one of the operands is a null pointer and the other is not, they compare unequal: p==q returns true, p!=q returns false, the behavior of other operators is unspecified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
Si les pointeurs p et q point à des membres de la même matrice ou a[i] a[j] et une delà de l'extrémité de la rangée, ils sont comparés aux résultats de pointeurs est le même que le résultat de la comparaison des indices: si i<j==true puis {{{1}}} .
Original:
If the pointers p and q point to members of the same array a[i] and a[j] or one past the end of the array, they results of comparing the pointers is the same as the result of comparing the indexes: if i<j==true then {{{1}}}.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
Si les pointeurs p et q point de non-membres de données statiques au sein de la même catégorie ou sous-objets de base différentes dans la même classe dérivée, ou à leurs membres ou sous-objets, de manière récursive, et si les membres pointés / sous-objets ont le même contrôle d'accès (par exemple, à la fois public:), et la classe n'est pas un syndicat, alors le pointeur sur le sous-objet par la suite déclaré / membre supérieur compare le pointeur sur le sous-objet précédemment déclarées / membre. En d'autres termes, les membres du groupe dans chacun des trois modes d'accès sont placées en mémoire dans l'ordre de déclaration .
Original:
If the pointers p and q point to non-static data members within the same class or different base subobjects within the same derived class, or to their members or subobjects, recursively, and if the pointed-to members/subobjects have the same access control (e.g. both public:), and the class is not a union, then the pointer to the later declared subobject/member compares greater than the pointer to the earlier declared subobject/member. In other words, class members in each of the three access modes are positioned in memory in order of declaration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
Si les pointeurs p et le point q aux membres de la union même, elles sont égales (typiquement une conversion explicite pour void* est requis pour l'un des opérandes)
Original:
If the pointers p and q point to members of the same union, they compare equal (typically an explicit conversion to void* is required for one of the operands)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
Si l'un des pointeurs est un pointeur vers void et les deux pointeurs pointent à la même adresse ou les deux sont des pointeurs nuls, ils comparent l'égalité .
Original:
If one of the pointers is a pointer to void and both pointers point to the same address or are both null pointers, they compare equal.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
Si deux constantes pointeur nul, on constate qu'ils sont équivalentes .
Original:
If two null pointer constants are compared, they compare equal.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
9)
Si les deux opérandes sont des pointeurs vers membre (objet ou la fonction), elles sont égales si elles soulignent toutes deux le même membre de la classe la plus dérivée .
Original:
If both operands are pointers to member (object or function), they compare equal if they both point to the same member of the most derived class.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
10)
Dans le cas contraire (si les pointeurs pointer vers des objets dans des tableaux différents, ou à des fonctions différentes, ou aux membres de certains objets avec contrôle d'accès différent, etc), les résultats de p<q, p>q, p<=q et p>=q ne sont pas précisés, et p!=q retours false.
Original:
Otherwise (if the pointers point to objects in different arrays, or to different functions, or to members of some object with different access control, etc), the results of p<q, p>q, p<=q, and p>=q are unspecified, and p!=q returns false.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#include <iostream> struct Foo { int n1; int n2; }; union Union { int n; double d; }; int main() { std::cout << std::boolalpha; char a[4] = "abc"; char* p1 = &a[1]; char* p2 = &a[2]; std::cout << "Pointers to array elements: p1 == p2 " << (p1 == p2) << ", p1 < p2 " << (p1 < p2) << '\n'; Foo f; int* p3 = &f.n1; int* p4 = &f.n2; std::cout << "Pointers to members of a class: p3 == p4 " << (p3 == p4) << ", p3 < p4 " << (p3 < p4) << '\n'; Union u; int* p5 = &u.n; double* p6 = &u.d; std::cout << "Pointers to members of a union: p5 == (void*)p6 " << (p5 == (void*)p6) << ", p5 < p6 " << (p5 < (void*)p6) << '\n'; }
Résultat :
Pointers to array elements: p1 == p2 false, p1 < p2 true Pointers to members of a class: p3 == p4 false, p3 < p4 true Pointers to members of a union: p5 == (void*)p6 true, p5 < p6 false
Notes
Parce que ce groupe les opérateurs de gauche à droite, le a<b<c expression est analysée (a<b)<c, et non a<(b<c) ou (a<b)&&(b<c) .
Original:
Because these operators group left-to-right, the expression a<b<c is parsed (a<b)<c, and not a<(b<c) or (a<b)&&(b<c).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Une exigence commune définie par l'utilisateur pour operator< est strict ordonnancement faible. En particulier, cela est requis par les algorithmes standards et des conteneurs qui travaillent avec des types LessThanComparable: std::sort, std::max_element, std::map, etc
Original:
A common requirement for user-defined operator< is strict ordonnancement faible. In particular, this is required by the standard algorithms and containers that work with LessThanComparable types: std::sort, std::max_element, std::map, etc.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bien que les résultats de la comparaison des pointeurs d'origine aléatoire (par exemple, pas tout en montrant les membres du même réseau) n'est pas spécifié, de nombreuses implémentations fournissent totale ordre strict de pointeurs, par exemple, si elles sont appliquées comme des adresses au sein de l'espace d'adressage virtuel continue. Ces implémentations qui ne sont pas (par exemple, où tous les bits du pointeur font partie d'une adresse mémoire et doivent être ignorées pour la comparaison, ou un calcul supplémentaire est nécessaire ou non pointeur et un entier n'est pas une relation 1 à 1), fournissent un spécialisation des std::less pour les pointeurs qui a cette garantie. Cela permet d'utiliser tous les pointeurs d'origine aléatoire comme clés dans des conteneurs standards associatifs tels que std::set ou std::map .
Original:
Although the results of comparing pointers of random origin (e.g. not all pointing to members of the same array) is unspecified, many implementations provide totale ordre strict of pointers, e.g. if they are implemented as addresses within continuous virtual address space. Those implementations that do not (e.g. where not all bits of the pointer are part of a memory address and have to be ignored for comparison, or an additional calculation is required or otherwise pointer and integer is not a 1 to 1 relationship), provide a specialization of std::less for pointers that has that guarantee. This makes it possible to use all pointers of random origin as keys in standard associative containers such as std::set or std::map.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bibliothèque standard
Les opérateurs de comparaison sont surchargées pour de nombreuses classes dans la bibliothèque standard .
Original:
Comparison operators are overloaded for many classes in the standard library.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
| checks whether the objects refer to the same type (fonction membre publique de std::type_info) [edit]
| |
compare deux Original: compares two The text has been machine-translated via Google Translate. (fonction) | |
compare error_conditions et error_codes Original: compares error_conditions and error_codes The text has been machine-translated via Google Translate. (fonction) | |
compare lexicographiquement les valeurs de la paire Original: lexicographically compares the values in the pair The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le tuple Original: lexicographically compares the values in the tuple The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare le contenu Original: compares the contents The text has been machine-translated via Google Translate. (fonction membre publique de std::bitset) [edit]
| |
compare deux instances du programme d'allocation Original: compares two allocator instances The text has been machine-translated via Google Translate. (fonction membre publique de std::allocator) [edit]
| |
compare à un autre ou avec Original: compares to another The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare avec un autre ou avec Original: compares with another The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare avec une std::function Original: compares an std::function with The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux durées Original: compares two durations The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux points dans le temps Original: compares two time points The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux instances scoped_allocator_adaptor Original: compares two scoped_allocator_adaptor instances The text has been machine-translated via Google Translate. (fonction membre publique de std::scoped_allocator_adaptor) [edit]
| |
compare les objets sous-jacents std::type_info Original: compares the underlying std::type_info objects The text has been machine-translated via Google Translate. (fonction membre publique de std::type_index) [edit]
| |
compare lexicographiquement deux chaînes Original: lexicographically compares two strings The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
comparaison d'égalité entre les objets locale Original: equality comparison between locale objects The text has been machine-translated via Google Translate. (fonction membre publique de std::locale) [edit]
| |
compare lexicographiquement les valeurs dans le array Original: lexicographically compares the values in the array The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le deque Original: lexicographically compares the values in the deque The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le forward_list Original: lexicographically compares the values in the forward_list The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le list Original: lexicographically compares the values in the list The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le vector Original: lexicographically compares the values in the vector The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le map Original: lexicographically compares the values in the map The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le multimap Original: lexicographically compares the values in the multimap The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le set Original: lexicographically compares the values in the set The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le multiset Original: lexicographically compares the values in the multiset The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare les valeurs de la unordered_map Original: compares the values in the unordered_map The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare les valeurs de la unordered_multimap Original: compares the values in the unordered_multimap The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare les valeurs de la unordered_set Original: compares the values in the unordered_set The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare les valeurs de la unordered_multiset Original: compares the values in the unordered_multiset The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le queue Original: lexicographically compares the values in the queue The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare lexicographiquement les valeurs dans le stack Original: lexicographically compares the values in the stack The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare deux reverse_iterators pour l'égalité Original: compares two reverse_iterators for equality The text has been machine-translated via Google Translate. (fonction générique) | |
reverse_iterators commandes Original: orders reverse_iterators The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux Original: compares two The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux istream_iterators Original: compares two istream_iterators The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux istreambuf_iterators Original: compares two istreambuf_iterators The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux nombres complexes ou un complexe et un scalaire Original: compares two complex numbers or a complex and a scalar The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare deux valarrays ou un valarray avec une valeur Original: compares two valarrays or a valarray with a value The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
compare les états internes des deux moteurs de nombres pseudo-aléatoires Original: compares the internal states of two pseudo-random number engines The text has been machine-translated via Google Translate. (fonction) [edit] | |
compare deux objets de distribution Original: compares two distribution objects The text has been machine-translated via Google Translate. (fonction) [edit] | |
compare les valeurs lexicographiquement dans le récipient Original: lexicographically compares the values in the container The text has been machine-translated via Google Translate. (fonction) [edit] | |
compare lexicographiquement les valeurs dans le résultat deux match Original: lexicographically compares the values in the two match result The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux Original: compares two The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux Original: compares two The text has been machine-translated via Google Translate. (fonction générique) | |
compare deux objets Original: compares two The text has been machine-translated via Google Translate. (fonction) | |
automatically generates comparison operators based on user-defined operator== and operator< (fonction générique) [edit] | |
Voir aussi
| Opérateurs ordinaires | ||||||
|---|---|---|---|---|---|---|
| affectation | incrémentation décrémentation |
arithmétique | logique | comparaison | accès aux membre | autre |
|
|
|
|
|
|
|
|
| Opérateurs spéciaux | ||||||
|
static_cast convertit un type dans un autre type compatible dynamic_cast convertit une classe de base virtuelle dans une classe dérivée const_cast convertit un type dans un type compatible avec des cv-qualifiers différents reinterpret_cast convertit un type dans un type incompatibles new allocation de la mémoire delete libère de la mémoire sizeof récupère la taille d'un type sizeof... récupère la taille d'un paquet de paramètres (depuis C++11) typeid récupère les informations de type d'un type noexcept vérifie si une expression peut lancer une exception (depuis C++11) alignof récupère les conditions d'alignement d'un type (depuis C++11) | ||||||