久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

什么是"for (const auto &s : strs) {} &quo

What does quot; for (const auto amp;s : strs) {} quot; mean?(什么是for (const auto amp;s : strs) {} quot;意思是?)
本文介紹了什么是"for (const auto &s : strs) {} "意思是?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

for (const auto &s : strs) 是什么意思?冒號 : 的作用是什么?

What does for (const auto &s : strs) mean? What is the function of colon :?

vector<string> &strs;
for (const auto &s : strs){
   //
}

推薦答案

它實際上是一個 C++11 特性,稱為基于范圍的 for 循環(huán)".

It's actually a C++11 feature called "range-based for-loops".

在這種情況下,它基本上是一個更容易編寫的替代品:

In this case, it's basically an easier-to-write replacement for:

// Let's assume this vector is not empty.
vector<string> strs;

const vector<string>::iterator end_it = strs.end();

for (vector<string>::iterator it = strs.begin(); it != end_it; ++it) {
  const string& s = *it;
  // Some code here...
}

: 是新語法的一部分.

在左側(cè),您基本上有一個變量聲明,它將綁定到向量的元素,而在右側(cè),您有一個要迭代的變量(也稱為范圍表達(dá)式").

On the left you basically have a variable declaration that will be bound to the elements of the vector and one the right you have the variable to iterate on (also called "range expression").

以下是解釋范圍表達(dá)式的先決條件的鏈接文檔的摘錄:

Here is an excerpt of the linked documentation that explains the prerequisites for the range-expressions:

range_expression 被評估以確定要迭代的序列或范圍.序列中的每個元素依次被取消引用并分配給具有 range_declaration 中給出的類型和名稱的變量.

range_expression is evaluated to determine the sequence or range to iterate. Each element of the sequence, in turn, is dereferenced and assigned to the variable with the type and name given in range_declaration.

begin_expr 和 end_expr 定義如下:

begin_expr and end_expr are defined as follows:

如果__range是一個數(shù)組,則begin_expr是__range,end_expr是(__range + __bound),其中__bound是數(shù)組中元素的個數(shù)(如果數(shù)組大小未知或類型不完整,程序就出錯了-形成)

If __range is an array, then begin_expr is __range and end_expr is (__range + __bound), where __bound is the number of elements in the array (if the array has unknown size or is of an incomplete type, the program is ill-formed)

如果 __range 的類型是具有 begin 或 end 成員函數(shù)之一或兩者的類類型,則 begin_expr 是 __range.begin() 而 end_expr 是 __range.end();

If __range's type is a class type with either or both a begin or an end member function, then begin_expr is __range.begin() and end_expr is __range.end();

否則,begin_expr 是 begin(__range) 和 end_expr 是 end(__range),它們是通過參數(shù)依賴查找找到的,std 作為關(guān)聯(lián)的命名空間.

Otherwise, begin_expr is begin(__range) and end_expr is end(__range), which are found via argument-dependent lookup with std as an associated namespace.

請注意,由于所有這些,基于范圍的 for 循環(huán)也支持迭代 C 數(shù)組,因為 std::begin/std::end 也適用于這些數(shù)組.

Note that thanks to all this, range-based for loops also support iterating over C arrays as std::begin/std::end works with those too.

這篇關(guān)于什么是"for (const auto &amp;s : strs) {} &quot;意思是?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數(shù)學(xué)式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區(qū)別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達(dá)式中的變量聲明)
主站蜘蛛池模板: 草草视频在线观看 | 一区二区三区四区不卡 | 99精品一区二区 | 亚洲日本欧美日韩高观看 | 国产欧美在线观看 | 成年网站在线观看 | 96av麻豆蜜桃一区二区 | 国产精品视频网 | 日韩中文视频 | 国产在线激情视频 | 日韩午夜在线观看 | 亚洲 欧美 日韩 在线 | 操久久 | 一级黄在线观看 | 日韩免费视频一区二区 | 国产网站在线免费观看 | 欧美在线观看网站 | 爱爱免费视频网站 | 久久国产精品一区二区三区 | 国产女人与拘做受免费视频 | 精品久久国产 | 欧美三级久久久 | 国产激情91久久精品导航 | 欧美日韩亚洲一区 | 午夜免费福利片 | 亚洲国产成人精品在线 | 精品一级 | 在线国产视频 | a级免费观看视频 | 在线不卡视频 | 欧美特级黄色 | 99精品国产一区二区三区 | 天天澡天天狠天天天做 | 亚洲码欧美码一区二区三区 | 久久综合影院 | 一区二区三区四区免费在线观看 | 在线中文一区 | 国产精品99一区二区 | 奇米影视77 | 国产在线观看一区二区三区 | 999久久久久久久久 国产欧美在线观看 |