c++ - Using template parameter in a generic lambda -
allows the following extension as an extension:
// a functional Object that will add two types of types of objects auto plus = [] & lt; Typename T & gt; (TA, TB) {return a + b; }; 2012 Proposal for Normal Lambda, we see the syntax which allows the above: overload ([] T> However, since it is a The extension is clear, so the syntax is clearly absent (or not allowed). In what situations will be useful when we have auto, and why the syntax is absent (or not allowed)?
It seems that C + 14 polymos Fact lambdas are only more compressed.
You can reproduce the effect of your sample position like the following:
struct A {}; struct B {} ; Int operator + (A, A) {return1;} int operator + (b, b) {return2;} int operator + (a, b) {return 3;} int operator + (b, a) {return 4}} int main () {auto add = [] (Auto A, Deletytype (A) B) Return to {A + B;} Auto Flexible_and = [] (Auto A, Auto B) {A + B;} ; (A {}, a {}); // work add (b {}, b {}); // work add (a {}, b {}); // Eks does not work Ible_add (A {} A {}); // works flexible_add (B {}, B {}); // works flexible_add (a {}, b {}); // Job Auto Deref = [] (Auto * A) {Return * A; }; Int Fu {}; AA; BB; Deref (& amp; foo); // Work Deaf (and A); // Work Deaf (& amp; amp; b); // Work Deaf (Foo); // Deaf (A); // Deref (B); // does not work}
However in many cases where the GCC extension is more efficient, not only in the case of your use (where it fits more naturally) For example, about non-type template parameters:
#include & lt; Cstddef & gt; # Include & lt; Utility & gt; # Include & lt; Iostream & gt; Zero print (std :: initializer_list & lt; std :: size_t & gt; IL) {for (auto & amp; elem: il) std :: cout & lt; & Lt; Elem & lt; & Lt; Std :: endl; } Int main () {auto indexed_lambda = [] & lt; Std :: size_t ... is & gt; (Std :: index_sequence is <... ... gt;) {print ({is ...}); }; Indexed_lambda (std :: make_index_sequence & lt; 5 & gt; {}); }
& Lt; Typename r & gt; (R (*) ()) {}; Accept_no_args_fun_only (foo); }
Variations:
#include & lt; Tupal & gt; #include & lt; Vector & gt; Int main () {auto accept_vector = [] (std :: vector & lt; auto & gt; & amp; amp;);}}; // Uncontrolled placeholder with compressed TS, but not variadic auto accept_tuple = [] & lt; Typename ... Args & gt; (Std :: tuple & lt; ergus ... & gt; & amp; amp; amp; amp;);}}; Accept_vector (std :: vector {42}); Accept_tuple (std :: tuple {42}); }
I do not know the discussion of the involvement of Generic Lambadas, but I can see one thing: is the price of such an extension, when the present Most uses in syntax include cases, in essence, and suitable for lambda intentions, often for small snippets of code.
Edit GCC extension has been decided to become part of C ++:
-
Comments
Post a Comment