Hi, > >The xsubpp compiler doesn't support C++'s template facilities. > >We need to define typemaps for each template instance as follows: > > > >typedef vector<int> IntVector; > >typedef vector<string> StringVector; > > > >IntVector T_INT_VETOR > >StringVector T_STR_VECTOR > > With a little work I am sure we could avoid the typedef > and have typemap just say > > vector<int> T_VECTOR_INT > vector<string> T_VECTOR_STRING
It seems that Inline::CPP doesn't support a typemap like that. I got the following enrror when didn't use typedef. Can't locate auto/main/test_int_vector.al in @INC... The xsubpp doesn't consider C++ namespaces, and hence treat vector<int> differently from std::vector<int>. Therefore I think using typedef still have a little effectiveness. > The structure there is a feature of vector-ness. The only > part that differs is the element to/from SV conversion. Yes I knew that, but couldn't work out a solution. > You cannot overload on return type unfortunately, so guts > a generic T_VECTOR might look like > > template elemtype > .... > elemtype elem; > sv_to_type(sv,elem); > var.push_back(elem); > > The fun part of that is trying to devise a template scheme so that element types > of int, char, long etc do SvIV () while char *, string etc. do SvPV > and float, double to SvNV(). Might be easier just to have a set of > overloaded functions: > > inline void sv_to_type(SV *sv,int &elem) { elem = SvIV(sv) } > inline void sv_to_type(SV *sv,double &elem) { elem = SvNV(sv) } That's an interesting idea, but still has a redundancy. I think I want to apply existing typemaps to each template element, but it requires the xsubpp to scan code recursively, and process additional task. If I have a good idea for that, I'll try to write a patch for the xsubpp. > It probably makes sense (it often does IMHO) to make the typemap call > a function - that function can be in C++ part of the .xs file and > so be overloaded or templated in C++ way - but we need to find a way to > get $elemtype in this fragment: > > T_VECTOR > $elemtype dummy; > sv_to_vector($arg,$var,dummy) > > By looking at the xsubpp code we _may_ be able to find a way to fish > $elemtype out of vector<elemtype> -- SH <[EMAIL PROTECTED]> Livin' on the EDGE Co., Ltd.