Increment/decrement operators
提供: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. |
インクリメント/デクリメント演算子インクリメントまたはデクリメントしたオブジェクトの値.
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); |
| ||||
[編集] 説明
プリインクリメントと'プリデクリメント演算子インクリメントまたはデクリメントしたオブジェクトの値と結果への参照を返します.
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.
ポストインクリメントとポストデクリメント、オブジェクト、インクリメントまたはデクリメントしたオブジェクトの値のコピーが作成され、インクリメントまたはデクリメント前からコピーを返し.
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.
[編集] 内蔵前置演算子
Aよりbool他、オプションでのcv-修飾されたオブジェクト·タイプには、次の関数のシグネチャは、オーバーロードの解決に参加する毎に任意にvolatile修飾ポインタPごとに任意にvolatile修飾算術型の場合: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&) |
(廃止予定) | |
| P& operator++(P&) |
||
| A& operator--(A&) |
||
| P& operator--(P&) |
||
組み込みの前置インクリメントまたはデクリメント演算子のオペランドは非ブール演算型またはオブジェクト型を完了するには、ポインタの変更可能な左辺値(非const参照)でなければなりません。これらのオペランドについては、表現++xはx+=1とまったく同じですし、発現--xはx-=1とまったく同じです、つまり、結果は左辺値として返され、更新オペランドであり、算術演算子用に定義されたすべての算術変換規則とポインタ演算の規則が適用されます。.
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 算術演算子 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.
前置インクリメント演算子のオペランドが型boolである場合は、そこに設定されているにtrue(廃止予定).
Original:
If the operand of the preincrement operator is of type bool, it is set to true (廃止予定).
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よりbool他、オプションでのcv-修飾されたオブジェクト·タイプには、次の関数のシグネチャは、オーバーロードの解決に参加する毎に任意にvolatile修飾ポインタPごとに任意にvolatile修飾算術型の場合: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) |
(廃止予定) | |
| P operator++(P&, int) |
||
| A operator--(A&, int) |
||
| P operator--(P&, int) |
||
ビルトイン後置インクリメントまたはデクリメント演算子のオペランドは非ブール演算型またはオブジェクト型を完了するためにポインタの変更可能な左辺値(非const参照)でなければなりません。結果は、オペランドの元の値をコピーですprvalueです。副作用としては、この演算子は
argまたはarg += 1、それぞれインクリメントおよびデクリメントするため評価することによってであるかのように、引数arg -= 1の値が変更されます。すべての算術変換規則と算術演算子適用するために定義され、ポインタ演算のルール.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 算術演算子 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.
後置インクリメント演算子のオペランドが型boolである場合は、そこに設定されているにtrue(廃止予定).
Original:
If the operand of the postincrement operator is of type bool, it is set to true (廃止予定).
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.
[編集] 例
#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'; }
Output:
n = 5 n2 = 2 n3 = 4 n4 = 4
[編集] ノート
伴うため、副作用の、ビルトインインクリメント演算子とデクリメント演算子はルールのシーケンスに違反しているため、未定義の動作を避けるために注意して使用しなければなりません.
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 ルールのシーケンス.
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:
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.
[編集] 標準ライブラリ
インクリメント演算子とデクリメント演算子は、多くの標準的なライブラリー·タイプのオーバーロードされています。特に、すべての
Iteratorオーバーロード演算子+ +と毎BidirectionalIteratorオーバーロード演算子 - 、これらの演算子は特定のイテレータのno-opsのない場合でも、.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. | |
| 増分または減分ずつの原子値 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. (パブリックメンバ関数of std::atomic)
| |
| インクリメントまたはデクリメントするティック数 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. (パブリックメンバ関数of 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. | |
| 進歩イテレータ 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. (パブリックメンバ関数of std::raw_storage_iterator)
| |
| 進歩イテレータ 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. (パブリックメンバ関数of std::reverse_iterator)
| |
| デクリメントイテレータ 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. (パブリックメンバ関数of std::reverse_iterator)
| |
| no-op (パブリックメンバ関数of std::back_insert_iterator)
| |
| no-op (パブリックメンバ関数of std::front_insert_iterator)
| |
| no-op (パブリックメンバ関数of std::insert_iterator)
| |
| 進歩イテレータ 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. (パブリックメンバ関数of std::move_iterator)
| |
| デクリメントイテレータ 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. (パブリックメンバ関数of std::move_iterator)
| |
| 進歩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. (パブリックメンバ関数of std::istream_iterator)
| |
| no-op (パブリックメンバ関数of std::ostream_iterator)
| |
| 進歩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. (パブリックメンバ関数of std::istreambuf_iterator)
| |
| no-op (パブリックメンバ関数of std::ostreambuf_iterator)
| |
| 進歩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. (パブリックメンバ関数of std::regex_iterator)
| |
| 進歩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. (パブリックメンバ関数of std::regex_token_iterator)
| |
[編集] も参照してください
| Common operators | ||||||
|---|---|---|---|---|---|---|
| 代入 | incrementNJdecrement | 算術 | 論理 | 比較 | memberNJaccess | 他の |
|
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
| Special operators | ||||||
|
static_cast別の互換性のあるタイプ
に1型に変換します 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派生class
に仮想基底クラスに変換します 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異なるcvqualifiers
と互換性のある型に型変換されます 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互換性type
に型を変換します 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割り当て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割り当て解除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. sizeoftype
のサイズを照会します 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...パラメーターパック(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. typeidtype
の型情報を照会します 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式が例外(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タイプ(C + + 11以来)のクエリアラインメント要件を
Original: alignof queries alignment requirements of a type (C + + 11以来) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||