more tests
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5832 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
52a01518f1
commit
58a46d290f
3 changed files with 85 additions and 0 deletions
|
|
@ -21,6 +21,11 @@ namespace std
|
||||||
%template(pairii) pair<int, int>;
|
%template(pairii) pair<int, int>;
|
||||||
%template(pairA) pair<int, A*>;
|
%template(pairA) pair<int, A*>;
|
||||||
%template(mapA) map<int, A*>;
|
%template(mapA) map<int, A*>;
|
||||||
|
|
||||||
|
%template(paircA1) pair<const int, A*>;
|
||||||
|
%template(paircA2) pair<const int, const A*>;
|
||||||
|
%template(pairiiA) pair<int,pair<int, A*> >;
|
||||||
|
%template(pairiiAc) pair<int,const pair<int, A*> >;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
71
Examples/test-suite/python/lib_std_vector.i
Normal file
71
Examples/test-suite/python/lib_std_vector.i
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
%module lib_std_vector
|
||||||
|
|
||||||
|
%include "std_vector.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <numeric>
|
||||||
|
%}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
%template(IntVector) vector<int>;
|
||||||
|
%template(BoolVector) vector<bool>;
|
||||||
|
}
|
||||||
|
|
||||||
|
%template(DoubleVector) std::vector<double>;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
typedef float Real;
|
||||||
|
%}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
%template(RealVector) vector<Real>;
|
||||||
|
}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
double average(std::vector<int> v) {
|
||||||
|
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Real> half(const std::vector<Real>& v) {
|
||||||
|
std::vector<Real> w(v);
|
||||||
|
for (std::vector<Real>::size_type i=0; i<w.size(); i++)
|
||||||
|
w[i] /= 2.0;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void halve_in_place(std::vector<double>& v) {
|
||||||
|
std::transform(v.begin(),v.end(),v.begin(),
|
||||||
|
std::bind2nd(std::divides<double>(),2.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%template(IntPtrVector) std::vector<int *>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
%{
|
||||||
|
#include <iostream>
|
||||||
|
%}
|
||||||
|
|
||||||
|
%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<Test::B>; // works
|
||||||
|
%template(VecA) std::vector<Test::A*>; // Does not work
|
||||||
|
|
@ -15,3 +15,12 @@ for i in range(0,10):
|
||||||
|
|
||||||
halve_in_place(dv)
|
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<bool> mapping"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue