From: <wsf...@us...> - 2012-10-04 06:01:44
|
Revision: 13859 http://swig.svn.sourceforge.net/swig/?rev=13859&view=rev Author: wsfulton Date: 2012-10-04 06:01:38 +0000 (Thu, 04 Oct 2012) Log Message: ----------- More lambda support - for optional lambda declarators Modified Paths: -------------- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html branches/gsoc2009-matevz/Examples/test-suite/cpp0x_lambda_functions.i branches/gsoc2009-matevz/Source/CParse/parser.y Modified: branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html =================================================================== --- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2012-10-02 21:12:36 UTC (rev 13858) +++ branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2012-10-04 06:01:38 UTC (rev 13859) @@ -217,14 +217,29 @@ <H3><a name="Cpp0x_Lambda_functions_and_expressions"></a>7.2.8 Lambda functions and expressions</H3> -<p>SWIG correctly parses the Lambda functions syntax. For example:</p> +<p>SWIG correctly parses most of the Lambda functions syntax. For example:</p> <div class="code"><pre> +auto val = [] { return something; }; +auto sum = [](int x, int y) { return x+y; }; auto sum = [](int x, int y) -> int { return x+y; }; </pre></div> <p>The lambda functions are removed from the wrapper class for now, because of the lack of support for closures (scope of the lambda functions) in the target languages.</p> +<p> +Lambda functions used to create variables can also be parsed, but due to limited support of <tt>auto</tt> when +the type is deduced from the expression, the variables are simply ignored. +</p> + +<div class="code"><pre> +auto six = [](int x, int y) { return x+y; }(4, 2); +</pre></div> + +<p> +Better support should be available in a later release. +</p> + <H3><a name="Cpp0x_Alternate_function_syntax"></a>7.2.9 Alternate function syntax</H3> Modified: branches/gsoc2009-matevz/Examples/test-suite/cpp0x_lambda_functions.i =================================================================== --- branches/gsoc2009-matevz/Examples/test-suite/cpp0x_lambda_functions.i 2012-10-02 21:12:36 UTC (rev 13858) +++ branches/gsoc2009-matevz/Examples/test-suite/cpp0x_lambda_functions.i 2012-10-04 06:01:38 UTC (rev 13859) @@ -21,14 +21,14 @@ int thing = 0; #ifdef SWIG // Not strictly correct as captured variables should have non-automatic storage duration, ie shouldn't capture globals. gcc-4.7 warns about this, but we check that SWIG can parse this anyway. -auto lambda5 = [=,&thing]() { return thing;}; +auto lambda5 = [=,&thing]() { return thing; }; #else -auto lambda5 = [=]() { return thing;}; +auto lambda5 = [=]() { return thing; }; #endif void fn() { int stuff = 0; - auto lambdaxxxx = [=,&stuff]() { return thing;}; + auto lambdaxxxx = [=,&stuff]() { return thing; }; } auto lambda6 = [] (int a, int b) mutable { return a + b; }; auto lambda7 = [] (int x, int y) -> int { return x+y; }; @@ -40,6 +40,8 @@ auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2); auto lambda14 = [] () throw () {}; auto lambda15 = [] () mutable throw () {}; +auto lambda16 = [] { return thing; }; +auto lambda17 = [] { return thing; }(); int runLambda1() { return lambda1(5,6); @@ -72,10 +74,9 @@ %{ // TODO struct LambdaStruct { - static constexpr auto lambda_struct1 = [=]() { return thing;}; + static constexpr auto lambda_struct1 = [=]() { return thing; }; }; int(*lambda101notauto)(int, int) = [] (int a, int b) { return a + b; }; -auto lambda100 = [] { return thing;}; int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2); void lambda_init(int = ([=]{ return 0; })()); %} Modified: branches/gsoc2009-matevz/Source/CParse/parser.y =================================================================== --- branches/gsoc2009-matevz/Source/CParse/parser.y 2012-10-02 21:12:36 UTC (rev 13858) +++ branches/gsoc2009-matevz/Source/CParse/parser.y 2012-10-04 06:01:38 UTC (rev 13859) @@ -3292,18 +3292,23 @@ | decltype { $$ = $1; } ; -/* - Lambda functions and expressions, such as: - auto myFunc = [](int x, int y) -> int { return x+y; }; - auto myFunc = [](int x, int y) { return x+y; }; - auto myFunc = [](int x, int y) { return x+y; }(1, 2); -*/ +/* ------------------------------------------------------------ + Lambda functions and expressions, such as: + auto myFunc = [] { return something; }; + auto myFunc = [](int x, int y) { return x+y; }; + auto myFunc = [](int x, int y) -> int { return x+y; }; + auto myFunc = [](int x, int y) throw() -> int { return x+y; }; + auto six = [](int x, int y) { return x+y; }(4, 2); + ------------------------------------------------------------ */ cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const lambda_body lambda_tail { $$ = 0; } | storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail { $$ = 0; } + | storage_class AUTO idcolon EQUAL lambda_introducer lambda_body lambda_tail { + $$ = 0; + } ; lambda_introducer : LBRACKET { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |