Increment/decrement operators
De cppreference.com.
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Incrément / décrément incréments opérateurs ou décrémente la valeur de l'objet .
Original:
Increment/decrement operators increments or decrements the value of the object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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 | |||
| pre-increment | ++a
|
Yes | T& T::operator++(); | T& operator++(T& a); |
| pre-decrement | --a
|
Yes | T& T::operator--(); | T& operator--(T& a); |
| post-increment | a++
|
Yes | T T::operator++(int); | T operator++(T& a, int); |
| post-decrement | a--
|
Yes | T T::operator--(int); | T operator--(T& a, int); |
| ||||
[modifier] Explication
Pré-incrémentation et pré-décrémentation incréments opérateurs ou décrémente la valeur de l'objet et renvoie une référence au résultat .
Original:
pre-increment and pre-decrement operators increments or decrements the value of the object and returns a reference to the result.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Post-incrémentation et post-décrémentation crée une copie de l'objet, incrémente ou décrémente la valeur de l'objet et renvoie la copie à partir de l'avant incrémentation ou de décrémentation .
Original:
post-increment and post-decrement creates a copy of the object, increments or decrements the value of the object and returns the copy from before the increment or decrement.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Built-in des opérateurs de préfixe
Pour chaque type arithmétique option volatile qualifié
A autre que bool, et pour chaque P pointeur en option volatile qualifié pour type d'objet facultativement cv-qualifié, les signatures de fonction suivants participent à la résolution de surcharge:Original:
For every optionally volatile-qualified arithmetic type
A other than bool, and for every optionally volatile-qualified pointer P to optionally cv-qualified object type, 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.
You can help to correct and verify the translation. Click here for instructions.
| A& operator++(A&) |
||
| bool& operator++(bool&) |
(obsolète) | |
| P& operator++(P&) |
||
| A& operator--(A&) |
||
| P& operator--(P&) |
||
L'opérande d'un incrément de préfixe intégré ou opérateur de décrémentation doit être une lvalue modifiable (référence non-const) de type arithmétique non-booléenne ou un pointeur pour compléter type d'objet. Pour ces opérandes, le ++x expression est exactement équivalent à x+=1, et le --x expression est exactement équivalent à x-=1, c'est le résultat est l'opérande de mise à jour, retournée comme lvalue, et toutes les règles de conversion arithmétique et les règles de l'arithmétique des pointeurs définis pour appliquer opérateurs arithmétiques .
Original:
The operand of a built-in prefix increment or decrement operator must be a modifiable lvalue (non-const reference) of non-boolean arithmetic type or pointer to complete object type. For these operands, the expression ++x is exactly equivalent to x+=1, and the expression --x is exactly equivalent to x-=1, that is, the result is the updated operand, returned as lvalue, and all arithmetic conversion rules and pointer arithmetic rules defined for opérateurs arithmétiques apply.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Si l'opérande de l'opérateur pré-incrémentation est de bool type, il est mis à true (obsolète) .
Original:
If the operand of the preincrement operator is of type bool, it is set to true (obsolète).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Built-in opérateurs de suffixe
Pour chaque type arithmétique option volatile qualifié
A autre que bool, et pour chaque P pointeur en option volatile qualifié pour type d'objet facultativement cv-qualifié, les signatures de fonction suivants participent à la résolution de surcharge:Original:
For every optionally volatile-qualified arithmetic type
A other than bool, and for every optionally volatile-qualified pointer P to optionally cv-qualified object type, 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.
You can help to correct and verify the translation. Click here for instructions.
| A operator++(A&, int) |
||
| bool operator++(bool&, int) |
(obsolète) | |
| P operator++(P&, int) |
||
| A operator--(A&, int) |
||
| P operator--(P&, int) |
||
L'opérande d'un incrément intégré postfix ou opérateur de décrémentation doit être une lvalue modifiable (référence non-const) de type arithmétique non-booléenne ou un pointeur pour compléter type d'objet. Le résultat est un prvalue, qui est une copie de la valeur initiale de l'opérande. Comme un effet secondaire, cet opérateur modifie la valeur de son argument comme s'il
arg en évaluant arg += 1 ou arg -= 1, pour incrémenter et décrémenter respectivement. Toutes les règles de conversion arithmétique et les règles de l'arithmétique des pointeurs définis pour opérateurs arithmétiques applicables .Original:
The operand of a built-in postfix increment or decrement operator must be a modifiable lvalue (non-const reference) of non-boolean arithmetic type or pointer to complete object type. The result is a prvalue, which is a copy the original value of the operand. As a side-effect, this operator modifies the value of its argument
arg as if by evaluating arg += 1 or arg -= 1, for increment and decrement respectively. All arithmetic conversion rules and pointer arithmetic rules defined for opérateurs arithmétiques apply.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Si l'opérande de l'opérateur postincrement est bool type, il est mis à true (obsolète) .
Original:
If the operand of the postincrement operator is of type bool, it is set to true (obsolète).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Exemple
#include <iostream> int main() { int n = 1; int n2 = ++n; int n3 = ++ ++n; int n4 = n++; // int n5 = n++ ++; // compile error // int n5 = n + ++n; // undefined behavior std::cout << "n = " << n << '\n' << "n2 = " << n2 << '\n' << "n3 = " << n3 << '\n' << "n4 = " << n4 << '\n'; }
Résultat :
n = 5 n2 = 2 n3 = 4 n4 = 4
[modifier] Notes
En raison des effets secondaires impliqués, intégré dans les opérateurs d'incrémentation et de décrémentation doit être utilisé avec précaution pour éviter un comportement indéfini en raison de violations des séquençage règles .
Original:
Because of the side-effects involved, built-in increment and decrement operators must be used with care to avoid undefined behavior due to violations of séquençage règles.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parce que une copie temporaire de l'objet est construit pendant l'opération, pré-incrémentation ou pré-décrémentation opérateurs sont généralement plus efficaces dans des contextes où la valeur retournée n'est pas utilisé .
Original:
Because a temporary copy of the object is constructed during the operation, pre-increment or pre-decrement operators are usually more efficient in contexts where the returned value is not used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Bibliothèque standard
Les opérateurs d'incrémentation et de décrémentation sont surchargées pour de nombreux types de bibliothèques standard. En particulier, tout exploitant
Iterator surcharges + + et de chaque exploitant BidirectionalIterator surcharges -, même si ces opérateurs sont pas ops-pour l'itérateur particulier .Original:
Increment and decrement operators are overloaded for many standard library types. In particular, every
Iterator overloads operator++ and every BidirectionalIterator overloads operator--, even if those operators are no-ops for the particular iterator.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Original: overloads for arithmetic types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| incrémente ou décrémente la valeur atomique par une Original: increments or decrements the atomic value by one The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::atomic)
| |
| incrémente ou décrémente le nombre de cycles Original: increments or decrements the tick count The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::chrono::duration)
| |
Original: overloads for iterator types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| progrès de l'itérateur Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::raw_storage_iterator)
| |
| progrès de l'itérateur Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::reverse_iterator)
| |
| décrémente l'itérateur Original: decrements the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::reverse_iterator)
| |
| no-op (fonction membre publique de std::back_insert_iterator)
| |
| no-op (fonction membre publique de std::front_insert_iterator)
| |
| no-op (fonction membre publique de std::insert_iterator)
| |
| progrès de l'itérateur Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::move_iterator)
| |
| décrémente l'itérateur Original: decrements the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::move_iterator)
| |
| les progrès de la istream_iterator Original: advances the istream_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::istream_iterator)
| |
| no-op (fonction membre publique de std::ostream_iterator)
| |
| les progrès de la istreambuf_iterator Original: advances the istreambuf_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::istreambuf_iterator)
| |
| no-op (fonction membre publique de std::ostreambuf_iterator)
| |
| les progrès de la regex_iterator Original: advances the regex_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::regex_iterator)
| |
| les progrès de la regex_token_iterator Original: advances the regex_token_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::regex_token_iterator)
| |
[modifier] Voir aussi
| Common operators | ||||||
|---|---|---|---|---|---|---|
| affectation | incrémentation décrémentation | arithmétique | logique | comparaison | accès aux membre | autre |
|
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
| Opérateurs spéciaux | ||||||
|
static_cast convertit un type à un autre
type compatible Original: static_cast converts one type to another compatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. dynamic_cast convertit classe de base virtuelle à class
dérivée Original: dynamic_cast converts virtual base class to derived class The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. const_cast convertit un type à l'autre compatible avec cv qualifiers
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. reinterpret_cast convertit type type
incompatibles Original: reinterpret_cast converts type to incompatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. new alloue memory
Original: new allocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. delete libère memory
Original: delete deallocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof interroge la taille d'un type
Original: sizeof queries the size of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof... interroge la taille d'un Paquet de paramètre (depuis C++11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. typeid interroge les informations de type d'une type
Original: typeid queries the type information of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. noexcept vérifie si une expression peut jeter une exception (depuis C++11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. alignof requêtes exigences d'alignement d'un (depuis C++11) type
Original: alignof queries alignment requirements of a type (depuis C++11) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||