Friday 15 August 2014

c++ - How does generic lambda work in C++14? -


Normal lambda works in C ++ 14 standard ( auto as an argument type Keywords)?

Is it based on the C ++ template, where a new function is generated for each different logic type compiler with the same body, but the type of replacement (compile-time polymorphism) or it's Java Is similar to generic (type arasher)?

Code example:

  Auto glambda = [] (Auto A) {return; };    

generic lambadass C ++ 14 < / Strong>.

Simply, in the closing type defined by Lambda expression, there will be a templated call operator instead of regular, non-template call operator of C ++ 'lambdas (of course, when auto parameter appears at least once in the list).

Then your example:

  Auto Globe = [] (Auto A) {Return; };   

Globe will create an example like this:

  class / * unnamed * / {public: template & lt; Typename T & gt; ; T Operator (TA) Const. {Return; }};   

The paragraph 5.1.2 / 5 of the C ++ 14 Standard Draft N 36 9 states how the closed operator of the given lambda expression has defined the call operator: < Blockquote>

The off type for a non-normal lambda-expression is a public inline function call operator (13.5.4), whose parameter and return type are described by parameter-declaration-section of lambda-expression and subsequent sequence- Order Normal Lamp For Da, are an invention of template-parameters for a public inline function call operator member template (L4k5k2) the type of closure, which is template-parameter-list independent of each event lambda ??? ? Parameter-Announcement-section, in the order of appearance The invented type template-parameter is a parameter pack if the related parameter declaration declares a function parameter pack (8.3.5). Function call operator template returns type and function parameters, followed by lambda-expression follow-returns-type and parameter-declaration, parameter-declaration-related explanation clause with the name of template-parameter.

Finally:

Is it similar to templates, where each different logic type creates a function with compiler is the same body but changing types Or is it similar to the generic of Java?

As the above paragraph states, Generic Lambda is syntactic Chinese for unique, anonymous factories with just a templateed call operator. This should answer your question :)

No comments:

Post a Comment