Range-based for loop (C + + 11以来)
提供: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. |
範囲でforループを実行し.
Original:
Executes a for loop over a range.
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.
いくつかのコンテナまたはリストから、例えば、値の範囲に渡って伝統的な<div class="t-tr-text"> forループ
オペレーティング読みやすい相当として使用.Original:
for loop
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
Original:
Used as a more readable equivalent to the traditional
forループ</div> operating over a range of values, for example, from some container or list.
Original:
for loop
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
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.
目次 |
[編集] 構文
for ( range_declaration : range_expression) loop_statement
|
|||||||||
[編集] 説明
上記の構文は次のようなコードを生成します(
__range、__beginと__endのみ博覧会のためのものです):Original:
The above syntax produces code similar to the following (
__range, __begin and __end are for exposition only):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.
{
|
|||||||||
range_expressionは、シーケンスを決定するために評価されるか、または範囲がイテレートされてしまう。シーケンスの各要素を間接参照し、range_declarationで指定された型および名前を使用して、変数に代入されます.
Original:
The range_expression is evaluated to determine the sequence or range will be iterated over. Each element of the sequence is dereferenced, and assigned to the variable using the type and name given in the range_declaration.
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.
begin_exprとend_exprのいずれかであると定義されていますOriginal:
The
begin_expr and end_expr are defined to be either: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.
- (__range)と(__range + __bound)
__boundは、配列をバインドされた配列型のためOriginal:(__range) and (__range + __bound) for array types, where__boundis the array boundThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - begin(__range)とend(__range)、引数ルックアップルールに基づいて発見されている。標準コンテナの場合、これは終わるまでstd::beginに同等であるとstd::endどのターンコールで__range.begin()と__range.end().Original:begin(__range) and end(__range), which are found based on argument-lookup rules. For standard containers this ends up being equivalent to std::begin and std::end which in turn calls __range.begin() and __range.end().The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
range_expressionが一時を返す場合
はループを早く終了するために使用することができると__range右辺値参照に結合することによって示されるように、その有効期限は、ループの終わりまで拡張されてい.Original:
If range_expression returns a temporary, its lifetime is extended until the end of the loop, as indicated by binding to the rvalue reference
__range.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:
continue statement
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
Original:
Just as with a traditional loop,
ステートメントを破る
can be used to exit the loop early and Original:
break statement
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
ステートメントを続行します</div> can be used to restart the loop with the next element.
Original:
continue statement
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
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> #include <vector> int main() { std::vector<int> v = {0, 1, 2, 3, 4, 5}; for (int &i : v) // access by reference (const allowed) std::cout << i << ' '; std::cout << '\n'; for (auto i : v) // compiler uses type inference to determine the right type std::cout << i << ' '; std::cout << '\n'; for (int i : v) // access by value as well std::cout << i << ' '; std::cout << '\n'; }
Output:
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5