diff --git a/SWIG/Examples/test-suite/common.mk b/SWIG/Examples/test-suite/common.mk index 761dc26a0..cb2745d74 100644 --- a/SWIG/Examples/test-suite/common.mk +++ b/SWIG/Examples/test-suite/common.mk @@ -131,6 +131,7 @@ CPP_TEST_CASES += \ lib_cdata \ lib_cpointer \ lib_std_deque \ + lib_std_pair \ lib_std_string \ lib_std_vector \ lib_typemaps \ diff --git a/SWIG/Examples/test-suite/lib_std_pair.i b/SWIG/Examples/test-suite/lib_std_pair.i new file mode 100644 index 000000000..ca694468c --- /dev/null +++ b/SWIG/Examples/test-suite/lib_std_pair.i @@ -0,0 +1,62 @@ +%module lib_std_pair + +%include "std_pair.i" + +namespace std { + %template(IntPair) pair; +} + +%inline %{ + +/* Test the "out" typemap for pair */ +std::pair makeIntPair(int a, int b) { + return std::make_pair(a, b); +} + +/** + * There is no "out" typemap for a pointer to a pair, so + * this should return a wrapped instance of a std::pair + * instead of the native "array" type for the target language. + */ +std::pair * makeIntPairPtr(int a, int b) { + static std::pair p = std::make_pair(a, b); + return &p; +} + +/** + * There is no "out" typemap for a non-const reference to a pair, so + * this should return a wrapped instance of a std::pair instead of + * the native "array" type for the target language. + */ +std::pair& makeIntPairRef(int a, int b) { + static std::pair p = std::make_pair(a, b); + return p; +} + +/** + * There is no "out" typemap for a const reference to a pair, so + * this should return a wrapped instance of a std::pair + * instead of the native "array" type for the target language. + */ +const std::pair & makeIntPairConstRef(int a, int b) { + static std::pair p = std::make_pair(a, b); + return p; +} + +/* Test the "in" typemap for pair */ +int product1(std::pair p) { + return p.first*p.second; +} + +/* Test the "in" typemap for const pair& */ +int product2(const std::pair& p) { + return p.first*p.second; +} + +/* Test the "in" typemap for const pair* */ +int product3(const std::pair *p) { + return p->first*p->second; +} + +%} +