本文介绍了“对于(x:y)"是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在有关线程的互联网上四处寻找,我来到了有关线程的博客/教程中,但令我感到困惑的是他使用的这一行

So i was looking around on the interwebs about threads and i came to a blog/tutorial thing about threads but what confused me was this line that he used

for (auto& thread : threads)

不太确定该怎么做
这是我正在谈论的博客的链接 LINK
感谢谁为我回答了这个问题
PS,您还可以给我参考吗,这样我就可以阅读一下它的功能以及其他相关内容,这些内容在我搜索时似乎是盲目的

not really sure what that does
Here is a link to the blog i'm talking about LINK
Thanks to whoever answers this question for me
PS can you also give me a reference so i can read up on what that does and other related things I seem to be blind when searching for one

推荐答案

C ++ 11引入了一条新的迭代语句,即所谓的基于范围的 for 循环.它与普通的 for 循环不同之处在于,它仅使您可以访问范围的成员,而无需显式命名范围本身,也无需使用代理迭代器对象.具体来说,您不应在迭代过程中更改范围,因此此新循环记录了查看每个范围元素"的意图,并且不对范围本身做任何复杂的事情.

C++11 introduced a new iteration statement, the so-called range-based for loop. It differs from the ordinary for loop in that it only gives you access to the members of a range, without requiring you to name the range itself explicitly and without using proxy iterator objects. Specifically, you are not supposed to mutate the range during the iteration, so this new loop documents the intent to "look at each range element" and not do anything complicated with the range itself.

语法是这样的: for(decl x:r){/* body */} ,其中 decl 代表一些声明, r 是一个任意表达式.从功能上讲,它等效于以下传统循环:

The syntax is this: for (decl x : r) { /* body */ }, where decl stands for some declaration and r is an arbitrary expression. This is functionally mostly equivalent to the following traditional loop:

{
    auto && __r = r;

    using std::begin;
    using std::end;

    for (auto __it = begin(__r), __e = end(__r); __it != __e; ++__it)
    {
        decl x = *it;
        /* body */
    }
}

在特殊情况下,本机还支持数组和括号列表.

As a special case, arrays and braced lists are also supported natively.

这篇关于“对于(x:y)"是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:54