| import cpp20_abbreviated_template.*; | |
| public class cpp20_abbreviated_template_runme { | |
| static { | |
| try { | |
| System.loadLibrary("cpp20_abbreviated_template"); | |
| } 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); | |
| } | |
| } | |
| public static void main(String argv[]) { | |
| // Single auto parameter. | |
| if (cpp20_abbreviated_template.twice_int(5) != 10) | |
| throw new RuntimeException("twice_int(5)"); | |
| if (cpp20_abbreviated_template.twice_short((short)7) != 14) | |
| throw new RuntimeException("twice_short(7)"); | |
| // Two auto parameters with mixed types (int * double => double). | |
| if (cpp20_abbreviated_template.scale_id(3, 2.5) != 7.5) | |
| throw new RuntimeException("scale_id(3, 2.5)"); | |
| // Three auto parameters. | |
| if (cpp20_abbreviated_template.sum3_iii(1, 2, 3) != 6) | |
| throw new RuntimeException("sum3_iii(1, 2, 3)"); | |
| // Unnamed auto parameter. | |
| if (cpp20_abbreviated_template.unnamed_auto_int(99) != 42) | |
| throw new RuntimeException("unnamed_auto_int(99)"); | |
| // Constrained auto. | |
| if (cpp20_abbreviated_template.twice_numeric_int(7) != 14) | |
| throw new RuntimeException("twice_numeric_int(7)"); | |
| // Mixed type-constraints. | |
| if (cpp20_abbreviated_template.scale_mixed_id(3, 2.5) != 7.5) | |
| throw new RuntimeException("scale_mixed_id(3, 2.5)"); | |
| // Same type-constraint on multiple parms. | |
| if (cpp20_abbreviated_template.add_same_int(4, 5) != 9) | |
| throw new RuntimeException("add_same_int(4, 5)"); | |
| // Unnamed constrained auto. | |
| if (cpp20_abbreviated_template.unnamed_constrained_int(99) != 42) | |
| throw new RuntimeException("unnamed_constrained_int(99)"); | |
| // Constrained auto return type with explicit trailing return type. | |
| if (cpp20_abbreviated_template.half(10) != 5) | |
| throw new RuntimeException("half(10)"); | |
| if (cpp20_abbreviated_template.cube_constrained_int(3) != 27) | |
| throw new RuntimeException("cube_constrained_int(3)"); | |
| // Plain auto return type + constrained auto parameter + trailing return type. | |
| if (cpp20_abbreviated_template.twice_n_arrow_int(7) != 14) | |
| throw new RuntimeException("twice_n_arrow_int(7)"); | |
| // A decltype in the trailing return type names the parameter, so the %template argument gives the return type. | |
| if (cpp20_abbreviated_template.shadow_placeholder_double(2.5) != 2.5) | |
| throw new RuntimeException("shadow_placeholder_double(2.5)"); | |
| if (cpp20_abbreviated_template.second_placeholder_id(1, 2.5) != 2.5) | |
| throw new RuntimeException("second_placeholder_id(1, 2.5)"); | |
| if (cpp20_abbreviated_template.constrained_arrow_double(1.25) != 2.5) | |
| throw new RuntimeException("constrained_arrow_double(1.25)"); | |
| // Auto parameter pack - one wrapped parameter per type given to %template. | |
| if (cpp20_abbreviated_template.sum_all_ii(1, 2) != 3) | |
| throw new RuntimeException("sum_all_ii(1, 2)"); | |
| if (cpp20_abbreviated_template.sum_all_iii(1, 2, 3) != 6) | |
| throw new RuntimeException("sum_all_iii(1, 2, 3)"); | |
| if (cpp20_abbreviated_template.sum_numeric_ii(4, 5) != 9) | |
| throw new RuntimeException("sum_numeric_ii(4, 5)"); | |
| // Ordinary parameter ahead of an auto parameter pack. | |
| if (cpp20_abbreviated_template.offset_sum_ii(1, 2, 3) != 6) | |
| throw new RuntimeException("offset_sum_ii(1, 2, 3)"); | |
| // A pack followed by a plain parameter, which invents no template parameter of its own. | |
| if (cpp20_abbreviated_template.pack_then_plain_ii(1, 2, 7) != 207) | |
| throw new RuntimeException("pack_then_plain_ii(1, 2, 7)"); | |
| if (cpp20_abbreviated_template.pack_then_plain_numeric_ii(1, 2, 5.0) != 205) | |
| throw new RuntimeException("pack_then_plain_numeric_ii(1, 2, 5.0)"); | |
| // The size of each pack, which a wrong partition between them changes. | |
| if (cpp20_abbreviated_template.count_two_packs_ii(1, 2) != 200) | |
| throw new RuntimeException("count_two_packs_ii(1, 2)"); | |
| if (cpp20_abbreviated_template.count_two_packs_iii(1, 2, 3) != 300) | |
| throw new RuntimeException("count_two_packs_iii(1, 2, 3)"); | |
| if (cpp20_abbreviated_template.count_two_packs_renamed(1, 2, 3, 4) != 400) | |
| throw new RuntimeException("count_two_packs_renamed(1, 2, 3, 4)"); | |
| if (cpp20_abbreviated_template.count_pack_then_one_iii(1, 2, 3) != 203) | |
| throw new RuntimeException("count_pack_then_one_iii(1, 2, 3)"); | |
| if (cpp20_abbreviated_template.count_trailing_pack_ii(1, 2, 3) != 102) | |
| throw new RuntimeException("count_trailing_pack_ii(1, 2, 3)"); | |
| // Undecorated auto parameter pack. | |
| if (cpp20_abbreviated_template.sum_bare_ii(1, 2) != 3) | |
| throw new RuntimeException("sum_bare_ii(1, 2)"); | |
| if (cpp20_abbreviated_template.sum_bare_iii(1, 2, 3) != 6) | |
| throw new RuntimeException("sum_bare_iii(1, 2, 3)"); | |
| if (cpp20_abbreviated_template.unnamed_bare_ii(7, 8) != 42) | |
| throw new RuntimeException("unnamed_bare_ii(7, 8)"); | |
| // The pack determines the arity of the wrapper. | |
| try { | |
| cpp20_abbreviated_template.class.getMethod("sum_all_ii", int.class, int.class); | |
| } catch (NoSuchMethodException e) { | |
| throw new RuntimeException("sum_all_ii should take two arguments"); | |
| } | |
| try { | |
| cpp20_abbreviated_template.class.getMethod("sum_all_ii", int.class, int.class, int.class); | |
| throw new RuntimeException("sum_all_ii should take two arguments"); | |
| } catch (NoSuchMethodException expected) { | |
| } | |
| // An 'auto&&' pack wraps as pointer parms in Java, like any other 'auto&&' parm. | |
| try { | |
| cpp20_abbreviated_template.class.getMethod("sum_fwd_ii", SWIGTYPE_p_int.class, SWIGTYPE_p_int.class); | |
| } catch (NoSuchMethodException e) { | |
| throw new RuntimeException("sum_fwd_ii should take two pointer arguments"); | |
| } | |
| // Constrained 'Numeric auto' return without a trailing return type - SWIG cannot deduce so the function is ignored. | |
| try { | |
| cpp20_abbreviated_template.class.getMethod("half_numeric", int.class); | |
| throw new RuntimeException("half_numeric should be ignored (deduced return type)"); | |
| } catch (NoSuchMethodException expected) { | |
| } | |
| } | |
| } |