Increment/decrement operators — cppreference.com
De cppreference.com
<metanoindex/>
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.
| 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);
|
| ||||
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.
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.
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.
<tbody> </tbody>
|
|
||
|
|
(obsolète) | |
|
|
||
|
|
||
|
|
||
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.
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.
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.
<tbody> </tbody>
|
|
||
|
|
(obsolète) | |
|
|
||
|
|
||
|
|
||
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.
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.
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
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.
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.
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.
surcharges pour les types arithmétiques Original: overloads for arithmetic types The text has been machine-translated via Google Translate. | |
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. (fonction membre publique de std::atomic) [edit]
| |
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. (fonction membre publique de std::chrono::duration)
| |
surcharges pour les types d'itérateurs Original: overloads for iterator types The text has been machine-translated via Google Translate. | |
progrès de l'itérateur Original: advances the iterator The text has been machine-translated via Google Translate. (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. (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. (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. (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. (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. (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. (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. (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. (fonction membre publique de std::regex_token_iterator)
| |
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) | ||||||