auto

Is auto as a parameter in a regular function a GCC 4.9 extension?

℡╲_俬逩灬. 提交于 2019-11-26 08:52:07
问题 gcc 4.9 allows the following code, but gcc 4.8 and clang 3.5.0 reject it. void foo(auto c) { std::cout << c.c_str(); } I get warning: ISO C++ forbids use of \'auto\' in parameter declaration [-Wpedantic] in 4.9 but in 4.8 and clang I get error: parameter declared \'auto\' . 回答1: Yes, this is an extension. It's likely to be added to C++17 as part of the 'concepts' proposal, I believe. 回答2: This is Concepts Lite speak for template<class T> void foo(T c) { std::cout << c.c_str(); } The auto just

arrow operator (->) in function heading

ε祈祈猫儿з 提交于 2019-11-26 08:46:42
问题 I found such code: template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) { return a+b; } I figured with all details, that were new to me, but one. Tell me please, where can I read about, what does the arrow operator ( -> ) mean in function heading? I guess purely logically, that -> operator determines a type, that will be gotten by auto , but I want to get this straight, but can\'t find information. 回答1: In C++11, there are two syntaxes for function declaration: return

Does a declaration using “auto” match an extern declaration that uses a concrete type specifier?

a 夏天 提交于 2019-11-26 07:39:56
问题 Consider the following program: extern int x; auto x = 42; int main() { } Clang 3.5 accepts it (live demo), GCC 4.9 and VS2013 do not (live demo for the former). Who is right, and where is the correct behavior specified in the C++ Standard? 回答1: There's surprisingly little in the standard about this. About all we hear about redeclaration is: [C++11: 3.1/1]: A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations.

What does auto&& tell us?

◇◆丶佛笑我妖孽 提交于 2019-11-26 04:02:25
问题 If you read code like auto&& var = foo(); where foo is any function returning by value of type T . Then var is an lvalue of type rvalue reference to T . But what does this imply for var ? Does it mean, we are allowed to steal the resources of var ? Are there any reasonable situations when you should use auto&& to tell the reader of your code something like you do when you return a unique_ptr<> to tell that you have exclusive ownership? And what about for example T&& when T is of class type? I

How does generic lambda work in C++14?

孤街浪徒 提交于 2019-11-26 02:53:33
问题 How does generic lambda work ( auto keyword as an argument type) in C++14 standard? Is it based on C++ templates where for each different argument type compiler generates a new function with the same body but replaced types (compile-time polymorphism) or is it more similar to Java\'s generics (type erasure)? Code example: auto glambda = [](auto a) { return a; }; 回答1: Generic lambdas were introduced in C++14 . Simply, the closure type defined by the lambda expression will have a templated call

What are some uses of decltype(auto)?

不问归期 提交于 2019-11-26 02:41:31
问题 In c++14 the decltype(auto) idiom is introduced. Typically its use is to allow auto declarations to use the decltype rules on the given expression . Searching for examples of \"good\" usage of the idiom I can only think of things like the following (by Scott Meyers), namely for a function\'s return type deduction : template<typename ContainerType, typename IndexType> // C++14 decltype(auto) grab(ContainerType&& container, IndexType&& index) { authenticateUser(); return std::forward

Should the trailing return type syntax style become the default for new C++11 programs? [closed]

让人想犯罪 __ 提交于 2019-11-26 01:58:37
问题 C++11 supports a new function syntax: auto func_name(int x, int y) -> int; Currently this function would be declared as: int func_name(int x, int y); The new style does not seem to be widely adopted yet (say in the gcc stl) However, should this new style be preferred everywhere in new C++11-programs, or will it only be used when needed? Personally, I prefer the old style when possible, but a code-base with mixed styles looks pretty ugly. 回答1: There are certain cases where you must use a

How much is too much with C++11 auto keyword?

不羁的心 提交于 2019-11-26 01:44:18
问题 I\'ve been using the new auto keyword available in the C++11 standard for complicated templated types which is what I believe it was designed for. But I\'m also using it for things like: auto foo = std::make_shared<Foo>(); And more skeptically for: auto foo = bla(); // where bla() return a shared_ptr<Foo> I haven\'t seen much discussion on this topic. It seems that auto could be overused, since a type is often a form of documentation and sanity checks. Where do you draw the line in using auto

What is the type of lambda when deduced with “auto” in C++11?

蓝咒 提交于 2019-11-26 01:13:52
问题 I had a perception that, type of a lambda is a function pointer. When I performed following test, I found it to be wrong (demo). #define LAMBDA [] (int i) -> long { return 0; } int main () { long (*pFptr)(int) = LAMBDA; // ok auto pAuto = LAMBDA; // ok assert(typeid(pFptr) == typeid(pAuto)); // assertion fails ! } Is above code missing any point ? If not then, what is the typeof a lambda expression when deduced with auto keyword ? 回答1: The type of a lambda expression is unspecified. But they

auto.js用于手机app的js脚本

走远了吗. 提交于 2019-11-26 00:52:47
在搜索如何自动添加qq好友的时候看见了有人用auto.js的方法 https://www.bilibili.com/video/av28079383/?spm_id_from=333.788.videocard.5 搜索了autojs没想到还挺正式的有文档,在github上 https://hyb1996.github.io/AutoJs-Docs/#/ b站上有人做了教程 https://www.bilibili.com/video/av67357100 来源: https://www.cnblogs.com/lionli/p/11932846.html