[C++-sig] template constructor problem

David Abrahams david.abrahams at rcn.com
Sun Jan 20 02:36:23 CET 2002


I understand the problem. I think I can come up with something for you...

-Dave

----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at cci.lbl.gov>
To: <c++-sig at python.org>
Sent: Saturday, January 19, 2002 7:34 PM
Subject: Re: [C++-sig] template constructor problem


> > The (almost identical) code is again attached.
>
> Sorry for the lie. Here is the code:
>
> #include <boost/python/class_builder.hpp>
> #include <vector>
>
> template <typename VectorType>
> typename VectorType::value_type
> vector_min(VectorType const& v)
> {
>   typename VectorType::value_type result = v[0];
>   for(std::size_t i=1;i<v.size();i++) {
>     if (result > v[i]) result = v[i];
>   }
>   return result;
> }
>
> template <typename ValueType>
> struct stats
> {
>   template <typename VectorType> stats(VectorType const& vec) {
>   file://stats(std::vector<float> const& vec) {
>     m_min = vector_min(vec);
>   }
>   ValueType m_min;
> };
>
> BOOST_PYTHON_MODULE_INIT(template_constructor)
> {
>   boost::python::module_builder this_module("template_constructor");
>
>   boost::python::class_builder<std::vector<float> > py_svf(this_module,
"svf");
>   py_svf.def(boost::python::constructor<>());
>
>   boost::python::class_builder<stats<float> > py_stats(this_module,
"stats");
>   py_stats.def(boost::python::constructor<std::vector<float> const&>());
> }
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list