more tests

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5832 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-04-05 23:26:20 +00:00
commit 6abaf3fdb9
3 changed files with 85 additions and 0 deletions

View file

@ -21,6 +21,11 @@ namespace std
%template(pairii) pair<int, int>;
%template(pairA) pair<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*> >;
}

View 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

View file

@ -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<bool> mapping"