[C++-sig] template constructor problem

Ralf W. Grosse-Kunstleve rwgk at cci.lbl.gov
Sun Jan 20 01:34:48 CET 2002


> 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) {
  //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&>());
}




More information about the Cplusplus-sig mailing list