%module cpp17_enable_if_t // test use of enable_if_t but without full %template instantiation, that is no enable_if_t definition is parsed %inline %{ #if defined(_MSC_VER) && _MSC_VER < 1920 #define or || #define and && #endif #include typedef int node_t; typedef int position_t; template , bool> = true> void enableif1(const A a, const B b) {} // tests non-type template parameters within () brackets - was causing an infinite loop, issue #2418 template ), bool> = true> void enableif2(const A a, const B b) {} template || std::is_same_v), bool> = true> void enableif3(const A a, const B b) {} template or std::is_same_v) and (std::is_integral_v or std::is_same_v), bool> = true> void enableif4(const A a, const B b) {} template and std::is_integral_v), bool> = true> int enableif5(const A a, const B b) { return a + b; } void tester() { enableif5(10, 20); enableif5(10, 20); } %} // non-type template parameters working well in SWIG, below is a simple workaround as the 3rd parameter is defaulted for enable_if_t (which is just SFINAE to give a nice C++ compiler error) %template(enableif5) enableif5; // workaround (overriding default) %inline %{ // #1037 infinite loop template > void destId(T el) {} template = 3>> void destId(const T& el) {} %} %inline %{ // #961 no name for defaulted template parameter template::value>> void uuu() {} template::value>> void uuuE() {} template::value>::type> void vvv() {} template::value>::type> void vvvE() {} // More variations of enable_if and enable_if_t template::value>::type* = nullptr> void www() {} template::value, int> = 0> void xxx() {} enum TestEnum { Enum1 = 1, Enum2 }; struct TestStruct {}; void tester2() { uuu(); // uuu(); // compilation error uuuE(); // uuuE(); // compilation error vvv(); // vvv(); // compilation error vvvE(); // vvvE(); // compilation error www(); // www(); // compilation error xxx(); // xxx(); // compilation error } %} // Check fold expressions parse (#2868): #define FOLD_EXPR_TEST(OP, FUNC) \ template< \ typename... Ts, \ typename R = typename std::common_type_t, \ std::enable_if_t< \ (std::is_same_v,HalfInt> OP ...) \ && (std::is_constructible_v \ || std::is_convertible_v) \ >* = nullptr \ > \ constexpr inline R FUNC(const Ts&... t) { return std::min(static_cast(t)...); } FOLD_EXPR_TEST(+, f1) FOLD_EXPR_TEST(-, f2) FOLD_EXPR_TEST(*, f3) FOLD_EXPR_TEST(/, f4) FOLD_EXPR_TEST(%, f5) FOLD_EXPR_TEST(&, f6) FOLD_EXPR_TEST(|, f7) FOLD_EXPR_TEST(^, f8) FOLD_EXPR_TEST(<<, f9) FOLD_EXPR_TEST(>>, f10) FOLD_EXPR_TEST(&&, f11) FOLD_EXPR_TEST(||, f12) FOLD_EXPR_TEST(==, f13) FOLD_EXPR_TEST(!=, f14) FOLD_EXPR_TEST(>=, f15) FOLD_EXPR_TEST(<=, f16)