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

什么是`auto &&e` 在基于范圍的 for 循環

What does `auto amp;amp; e` do in range-based for-loops?(什么是`auto amp;amp;e` 在基于范圍的 for 循環中做什么?)
本文介紹了什么是`auto &&e` 在基于范圍的 for 循環中做什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

假設我在使用基于范圍的循環編程時的當前規則說

Assuming my current rule when programming with range-based loops says

盡可能使用 for(auto const &e :...)for(auto &e:...) 而不是 for(自動 a: ...).

Use for(auto const &e :...) or for(auto &e:...) when possible over for(auto a: ...).

我以我自己的經驗和這個問題為例.

I base this on my own experience and this question for example.

但是在閱讀了新的 簡潔的循環 我想知道,我不應該用 && 替換我的規則中的 & 嗎?正如此處所寫,這看起來像Meyers 的通用參考文獻.

But after reading about the new terse for loops I wonder, should I not replace my & in my rule with &&? As written here this looks like the Meyers' Universal References.

所以,我問自己,我的新規則是否應該是

So, I ask myself, should my new rule either be

盡可能使用 for(auto const &&e :...)for(auto &&e:...) ...

Use for(auto const &&e :...) or for(auto &&e:...) when possible ...

或者這并不總是有效,因此應該是相當復雜的

or does that not always work and therefore should rather be the quite complicated one

檢查 for(auto const &&e:...)for(auto &&e:...) 是否可行,然后考慮 for(auto const &e :...)for(auto &e:...),并且僅在需要時才使用引用.

Check if for(auto const &&e :...) or for(auto &&e:...) is possible, then consider for(auto const &e :...) or for(auto &e:...), and only when needed do not use references.

推薦答案

Howard Hinnant 此處.

When and if you should use auto&& in for loops has been explained very nicely by Howard Hinnant here.

這就留下了x

auto &&x = ...expr...

實際上是.并且像有函數模板定義一樣處理

actually is. And it is handled as if there there were a function template definition

template <class U> void f(const U& u);

并且x的類型是按照與u[§7.1.6.4.(7)]相同的規則推導出來的.

and the type of x is deduced by the same rules as u [§7.1.6.4.(7)].

這意味著它作為 RValue 參考處理,而是作為通用/轉發參考"處理.--參考折疊規則"申請.

This means it is not handled as a RValue Reference, but as a "Universal/Forwarding Reference" -- the "Reference Collapsing Rules" apply.

這也適用于

const auto &&x = ...expr...

作為 §7.1.6.4.(7) 中的例子,至少對于 const auto &x.

as the example in §7.1.6.4.(7) states, at least for const auto &x.

但是,正如 PiotrS 在問題評論中所說,任何限定詞都會使 URef-ness 無效:

But, as PiotrS says in the questions comments, any qualifiers nullifies the URef-ness:

不,因為template中的T都沒有.void f(const T&&) 是轉發引用,const auto&& 也不是.T&& 出現在參數聲明中的事實并不意味著它是轉發引用.只有沒有像 constvolatile 這樣的限定符的純 T&& 是轉發引用,這意味著它必須是 template;void f(T&&)auto&&,從不const T&&const auto&&代碼>

no, because neither T in template<class T> void f(const T&&) is a forwarding reference, nor const auto&& is. The fact that T&& occurs in parameter declaration does not imply it is forwarding reference. Only pure T&& with no qualifiers like const or volatile is forwarding reference, meaning it has to be template<class T> void f(T&&) or auto&&, and never const T&& or const auto&&

這篇關于什么是`auto &amp;&amp;e` 在基于范圍的 for 循環中做什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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;(比較運算符的數學式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 亚洲成人网在线观看 | 国产一区二区精 | 一级黄色生活视频 | av在线天堂 | 天天操夜夜操 | 狠狠骚| 欧洲妇女成人淫片aaa视频 | 成人在线看片 | 免费精品在线视频 | 精品国产乱码久久久久久88av | 亚洲自拍偷拍视频 | 国产欧美在线视频 | 亚洲精品久久久久中文字幕欢迎你 | 久久精品视频一区二区三区 | 亚洲九色 | 亚洲欧美中文字幕在线观看 | 久久久www成人免费无遮挡大片 | 久久99精品久久久久久 | 岛国在线免费观看 | 在线日韩av电影 | 亚洲欧美综合 | 91资源在线 | 国产精品福利网站 | 国产成人精品区一区二区不卡 | 国产欧美久久一区二区三区 | 国产免费拔擦拔擦8x高清 | 韩日一区二区三区 | 成人福利在线视频 | 午夜电影福利 | 草久久 | h视频在线观看免费 | 日韩在线不卡视频 | 国产精品久久久乱弄 | 亚洲精品乱码久久久久久按摩观 | 中文字幕免费视频 | 成人免费视频在线观看 | 久久99精品久久久久久 | 91久久久久久 | 国产一级片av | 羞羞的视频在线观看 | 久久久久久色 |