[C++-sig] template function
Luca Sbardella
luca.sbardella at gmail.com
Wed Aug 29 17:48:58 CEST 2007
Sure,
here is a code with the problem
#include <vector>
#include <boost/python.hpp>
#include <boost/python/wrapper.hpp>
#include <boost/python/detail/prefix.hpp>
#include <boost/python/converter/return_from_python.hpp>
#include <boost/python/call.hpp>
template<class T>
class dataserie {
public:
typedef T value_type;
typedef std::vector<T> container;
typedef typename container::iterator iterator;
typedef typename container::const_iterator const_iterator;
dataserie(){}
virtual ~dataserie(){}
bool empty() const {return m_data.empty();}
unsigned size() const {return m_data.size();}
const_iterator begin() const {return m_data.begin();}
const_iterator end() const {return m_data.end();}
template<class L>
L tolist() const {
L list;
for(const_iterator it = m_data.begin();it!=m_data.end();++it)
list.append(*it);
return list;
}
private:
container m_data;
};
template<class D>
void export_dataserie(const std::string& name) {
typedef dataserie<D> container;
typedef typename container::value_type value_type;
boost::python::class_<container>(name.c_str())
.def("__len__", &container::size)
.add_property("size", &container::size)
.add_property("empty", &container::empty)
.def("list", &container::tolist<
boost::python::list > )
;
}
BOOST_PYTHON_MODULE(testlib) {
export_dataserie<double>("test");
}
when I compile the file I get the following
make all
Building file: ../dataserie.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/python2.5 -I/usr/local/include -O0 -g3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"dataserie.d" -MT"dataserie.d" -o"dataserie.o"
"../dataserie.cpp"
../dataserie.cpp: In function 'void export_dataserie(const std::string&)':
../dataserie.cpp:45: error: expected primary-expression before '>' token
../dataserie.cpp:45: error: expected primary-expression before ')' token
line 45 is the one with
.def("list", &container::tolist< boost::python::list > )
Luca
On 29/08/2007, Stefan Seefeld <seefeld at sympatico.ca> wrote:
>
> Luca Sbardella wrote:
> > Thanks Dave,
> > but I did put a concrete type in the template argument.
> > My previous email was a bit confusing.
> > Here is the function template used for exporting
>
> [...]
>
> > In function 'void export_test(const std::string&)':
> > error: expected primary-expression before '>' token
> > error: expected primary-expression before ')' token
>
> It would be helpful if you would give a full (minimal)
> source code exhibiting the error, together with a complete
> error message (in particular, line numbers).
>
> Thanks,
> Stefan
>
> --
>
> ...ich hab' noch einen Koffer in Berlin...
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070829/9dc9fc1f/attachment.htm>
More information about the Cplusplus-sig
mailing list