[C++-sig] member function template question.

Jonathan Brandmeyer jbrandmeyer at earthlink.net
Thu Feb 19 21:05:25 CET 2004


On Thu, 2004-02-19 at 14:49, Ralf W. Grosse-Kunstleve wrote:
> Your example has several layers of complexity. I believe the main trick you
> need to know is how to use a cast to tell the compiler what you want. E.g.:
> 
>   template <typename FloatType>
>   bool
>   is_positive_definite(
>     vec3<FloatType> const& eigenvalues,
>     FloatType const& tolerance);
> 
>   def("is_positive_definite",
>     (bool(*)(vec3<double> const&, double const&)) is_positive_definite);


I've had good results with statements like this:
    def("is_positive_definite", &is_positive_definite<double>);

Far simpler than casting the function, IMO.

> This is a bit cumbersome but somehow you have to define which FloatType you
> want to use since you are crossing the boundary between compile-time
> polymorphism and runtime polymorphism.
> 
> If you don't like the casts you can also define thin wrappers. This works for
> both "normal" functions and member functions.
> 
> I don't know how this is handled by Pyste. Maybe someone else can help?
> 
> I am also not an expert on dealing with raw pointers, in particular void* needs
> special attention. I think there is something about void* in the FAQ that you
> might want to read.
> 
> Ralf
> 
> --- Hanz Meizer <steam at nurfuerspam.de> wrote:
> > Sorry to post so many questions, but I've run into something I couldn't 
> > decduce from looking through the documentation. Is it possible to wrap 
> > member function templates? Example class:
> 


-Jonathan Brandmeyer





More information about the Cplusplus-sig mailing list