问题标签 [auto]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - auto&& 告诉我们什么?
如果您阅读类似的代码
auto&& var = foo();
foo任何按类型值返回的函数在哪里T。然后var是一个右值引用类型的左值T。但这意味着var什么?这是否意味着,我们可以窃取资源var?是否有任何合理的情况,您应该使用auto&&类似的方式告诉读者您的代码,就像您在返回 aunique_ptr<>以告知您拥有独占所有权时所做的那样?例如什么T&&时候T是类类型?
auto&&我只是想了解,除了模板编程之外,是否还有其他用例;就像Scott Meyers 的文章Universal References中的示例中讨论的那样。
c++ - 为什么基于范围的 for 语句通过 auto&& 获取范围?
基于范围的for语句在§6.5.4 中定义为等效于:
其中range-init为基于范围的两种形式定义为for:
(该子句进一步指定了其他子表达式的含义)
为什么__range给出推导的类型auto&&?我的理解auto&&是,通过将表达式传递给std::forward. 但是,__range不会在任何地方通过std::forward. 它仅在获取范围迭代器时使用,作为__range、__range.begin()或begin(__range).
使用“通用参考”有什么好处auto&&?还auto&不够吗?
注意:据我所知,该提案没有说明auto&&.
c++ - 为什么我可以在私有类型上使用 auto ?
我对以下代码编译和运行感到惊讶(vc2012 & gcc4.7.2)
这段代码编译是否正确?为什么它是正确的?为什么我可以auto在私有类型上使用,而我不能使用它的名称(如预期的那样)?
c++ - 自动变量及其类型
我在一篇文章中找到了如何使用迭代器从容器中删除元素。迭代时:
为什么auto不使用类型 in auto next = it;?
我使用 VS10,而不是 C++11!
c++ - 为什么在“自动返回”功能中需要 decltype?
考虑这段代码:
我只是有一个非常简单的问题:为什么我需要在第二种方法(不使用的方法)中放入不同decltype()的后缀返回类型?add()add()
c++ - 自动使用无效
在这段代码中:
我从 gcc 4.7.1 收到错误:
任何想法为什么?那不应该被正确编译吗?
c++ - 使用 auto 公开私有类型:它在哪里有用?
在这个问题中,讨论了为什么公开私有类型auto:
完全符合 C++11 标准。我仍然不明白这个习语在实际应用程序中如何有用。 是否存在可以有效使用此成语的问题,或者应该将其视为关键字的“好奇”副作用?
c++ - ISO C++ 禁止声明没有自动迭代器类型的“it”?
我有这六行:
它们在 VS2012 中编译得非常好,但是在 centOS6 上的 GCC 中我得到了这些错误:
rcp_amxinfo 定义如下:
如何在 linux 上解决这些错误?
c++ - C++11 range-based for usage with auto
Possible Duplicate:
What is the advantage of using universal references in range-based for loops?
To iterate over the elements of a vector<int> to read them, I think the following usage of C++11 range-based for with auto is correct:
If the elements stored in the container are not simple integers, but something "heavier", like say std::strings, my understanding is that to iterate over them in a vector<string> the correct usage of range-based for + auto is:
The use of const & avoids useless deep-copies, and should be OK since the loop code is just observing the content of the vector.
Is my understanding correct so far?
Now, I saw code that uses another form of auto in range-based for loops: auto&&, e.g.:
What is this usage good for? What is the advantage of using r-value references (&&) with range-based for loops? In what cases should we use this style?
c++ - 尾随返回类型语法是否应该是所有函数的默认语法?
可能重复:
替代函数语法
在复杂的函数模板中,有时需要 C++11 尾随返回类型语法才能decltype在参数上使用,否则会为时已晚:
从现在开始总是使用这种新语法会不会更加一致,即使对于普通函数也是如此?
然后我们只需要处理一种函数语法而不是现代代码中的两种,我们可以弃用旧语法,就像我们弃用隐式 int 或隐式 using 声明一样。
为了使新语法更具吸引力,我们可以auto用一个更好的名称替换:
突然之间main,函数式程序员的签名看起来非常有吸引力:
我忽略了什么吗?尾随返回类型语法是否以某种我没有想到的方式较差?