diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f3414f931..5ee7df02f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -430,33 +430,34 @@ CPP_TEST_CASES += \ # C++0x test cases. CPP0X_TEST_CASES = \ - cpp0x_template_double_brackets \ + cpp0x_alternate_function_syntax \ + cpp0x_constexpr \ + cpp0x_decltype \ + cpp0x_default_delete \ cpp0x_explicit_conversion_operators \ - cpp0x_raw_string_literals \ - cpp0x_static_assert \ - cpp0x_template_explicit \ - cpp0x_uniform_initialization \ cpp0x_function_objects \ - cpp0x_strongly_typed_enumerations \ + cpp0x_initializer_list \ + cpp0x_raw_string_literals \ + cpp0x_result_of \ cpp0x_rvalue_reference \ cpp0x_rvalue_reference2 \ - cpp0x_variadic_templates \ - cpp0x_alternate_function_syntax \ - cpp0x_userdefined_literals \ - cpp0x_decltype \ - cpp0x_result_of \ - cpp0x_default_delete \ cpp0x_sizeof_object \ - cpp0x_initializer_list -# cpp0x_template_typedefs # not supported by any compiler yet -# cpp0x_hash_types # not fully implemented yet -# cpp0x_constructors # not supported by any compiler yet -# cpp0x_lambda_functions # not supported by GCC or MSVC yet -# cpp0x_null_pointer_constant # not supported by any compiler yet -# cpp0x_unrestricted_unions # not supported by any compiler yet -# cpp0x_smart_pointers # not supported by standard library yet -# cpp0x_constexpr # not supported by any compiler yet -# cpp0x_thread_local # not supported by any compiler yet + cpp0x_static_assert \ + cpp0x_strongly_typed_enumerations \ + cpp0x_template_double_brackets \ + cpp0x_template_explicit \ + cpp0x_uniform_initialization \ + cpp0x_userdefined_literals \ + cpp0x_variadic_templates + +# cpp0x_constructors \ # not supported by any compiler yet +# cpp0x_hash_tables \ # not fully implemented yet +# cpp0x_lambda_functions \ # not supported by GCC or MSVC yet +# cpp0x_null_pointer_constant \ # not supported by any compiler yet +# cpp0x_smart_pointers \ # not supported by standard library yet +# cpp0x_template_typedefs \ # not supported by any compiler yet +# cpp0x_thread_local \ # not supported by any compiler yet +# cpp0x_unrestricted_unions \ # not supported by any compiler yet # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index 7ca4c08d8..56235e9a6 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -5,30 +5,47 @@ */ %module cpp0x_lambda_functions -%inline %{ -struct A { - /* Defined lambda function with return value. */ - auto lambda1 = [](int x, int y) -> int { return x+y; }; +#pragma SWIG nowarn=SWIGWARN_LANG_NATIVE_UNIMPL - /* Defined lambda function without return value. - Return value is calculated by compiler, if the function contains a - single statement "return expr;". */ - auto lambda2 = [](int x, int y) { return x+y; }; -}; +%inline %{ +/* Defined lambda function with return value. */ +auto lambda1 = [](int x, int y) -> int { return x+y; }; + +/* Defined lambda function without return value. + Return value is calculated by compiler, if the function contains a + single statement "return expr;". */ +auto lambda2 = [](int x, int y) { return x+y; }; + +auto lambda3 = [&](int x, int y) { return x+y; }; +auto lambda4 = [=](int x, int y) { return x+y; }; +int thing = 0; +auto lambda5 = [=,&thing]() { return thing;}; int runLambda1() { - A myA; - return myA.lambda1(5,6); + return lambda1(5,6); } int runLambda2() { - A myA; - return myA.lambda2(5,6); + return lambda2(5,6); +} + +int runLambda3() { + return lambda3(5,6); +} + +int runLambda4() { + return lambda4(5,6); +} + +int runLambda5() { + thing++; + return lambda5(); } /* Inline defined lambda function. */ -int runLambda3() { +int runLambdaInline() { auto myLambda = [](int x, int y) { return x+y; }; return myLambda(5,6); } %} + diff --git a/Examples/test-suite/java/cpp0x_lambda_functions_runme.java b/Examples/test-suite/java/cpp0x_lambda_functions_runme.java new file mode 100644 index 000000000..79545f87e --- /dev/null +++ b/Examples/test-suite/java/cpp0x_lambda_functions_runme.java @@ -0,0 +1,28 @@ +import cpp0x_lambda_functions.*; + +public class cpp0x_lambda_functions_runme { + + static { + try { + System.loadLibrary("cpp0x_lambda_functions"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + private static void check(int received, int expected) { + if (expected != received) + throw new RuntimeException("check failed, expected: " + expected + " received: " + received); + } + + public static void main(String argv[]) + { + check(cpp0x_lambda_functions.runLambda1(), 11); + check(cpp0x_lambda_functions.runLambda2(), 11); + check(cpp0x_lambda_functions.runLambda3(), 11); + check(cpp0x_lambda_functions.runLambda4(), 11); + check(cpp0x_lambda_functions.runLambda5(), 1); + check(cpp0x_lambda_functions.runLambda5(), 2); + } +}