diff --git a/SWIG/Examples/test-suite/python/lib_std_map.i b/SWIG/Examples/test-suite/python/lib_std_map.i index 0cb84dbcf..e90a123e8 100644 --- a/SWIG/Examples/test-suite/python/lib_std_map.i +++ b/SWIG/Examples/test-suite/python/lib_std_map.i @@ -21,6 +21,11 @@ namespace std %template(pairii) pair; %template(pairA) pair; %template(mapA) map; + + %template(paircA1) pair; + %template(paircA2) pair; + %template(pairiiA) pair >; + %template(pairiiAc) pair >; } diff --git a/SWIG/Examples/test-suite/python/lib_std_vector.i b/SWIG/Examples/test-suite/python/lib_std_vector.i new file mode 100644 index 000000000..9b0a64bdb --- /dev/null +++ b/SWIG/Examples/test-suite/python/lib_std_vector.i @@ -0,0 +1,71 @@ +%module lib_std_vector + +%include "std_vector.i" + +%{ +#include +#include +#include +%} + +namespace std { + %template(IntVector) vector; + %template(BoolVector) vector; +} + +%template(DoubleVector) std::vector; + +%inline %{ +typedef float Real; +%} + +namespace std { + %template(RealVector) vector; +} + +%inline %{ + +double average(std::vector v) { + return std::accumulate(v.begin(),v.end(),0.0)/v.size(); +} + +std::vector half(const std::vector& v) { + std::vector w(v); + for (std::vector::size_type i=0; i& v) { + std::transform(v.begin(),v.end(),v.begin(), + std::bind2nd(std::divides(),2.0)); +} + +%} + +%template(IntPtrVector) std::vector; + + + +// +// +%{ +#include +%} + +%inline %{ + +namespace Test { +struct A { + virtual ~A() {} + virtual void f(const int i) const = 0; +}; + +struct B : public A { + void f(const int i) const + { std::cout << "B::f(int)\n"; } +}; +} +%} +%template(VecB) std::vector; // works +%template(VecA) std::vector; // Does not work diff --git a/SWIG/Examples/test-suite/python/lib_std_vector_runme.py b/SWIG/Examples/test-suite/python/lib_std_vector_runme.py index 1b196f550..e0e2d2482 100644 --- a/SWIG/Examples/test-suite/python/lib_std_vector_runme.py +++ b/SWIG/Examples/test-suite/python/lib_std_vector_runme.py @@ -15,3 +15,12 @@ for i in range(0,10): halve_in_place(dv) + +bv = BoolVector(4) +bv[0]= 1 +bv[1]= 0 +bv[2]= 4 +bv[3]= 0 + +if bv[0] != bv[2]: + raise RuntimeError,"bad std::vector mapping"