On May 15, 1:21 pm, mathieu <mathieu.malate...@gmail.com> wrote:
> On May 15, 12:48 pm, mathieu <mathieu.malate...@gmail.com> wrote:
>
>
>
> > Hi there,
>
> > I know this is not possible in c++. So my question, how should I
> > rewrite the following piece of code (without using a dummy class which
> > template parameter could be use for partial specialization).
>
> > template <typename TOut, typename TIn>
> > void InverseRescaleFunction(TOut *out, const TIn *in, double
> > intercept, double slope, size_t size)
> > { ... }
> > template <typename TOut>
> > void InverseRescaleFunction(TOut *out, const float *in, double
> > intercept, double slope, size_t size)
> > { ... }
>
> > Thanks !
>
> Ok found a solution:
>
> http://www.gotw.ca/publications/mill17.htm
>
> ...
> // Example 4: Illustrating Moral #2
> //
> template<class T>
> struct FImpl;
>
> template<class T>
> void f( T t ) { FImpl<T>::f( t ); } // users, don't touch this!
>
> template<class T>
> struct FImpl
> {
> static void f( T t ); // users, go ahead and specialize this};
>
> ...
>
> Sorry for the noise
> -M
For reference:
template<typename TOut, typename TIn>
struct FImpl;
template<typename TOut, typename TIn>
void InverseRescaleFunction(TOut *out, const TIn *in, double
intercept, double slope, size_t size)
{ FImpl<TOut,TIn>::InverseRescaleFunction(out,in,int ercept,slope,size); } //
users, don't touch this!
template<typename TOut, typename TIn>
struct FImpl
{
static void InverseRescaleFunction( TOut *out, const TIn *in,
double intercept, double slope, size_t size) // users, go ahead
and specialize this
{
....
}
};
template<typename TOut>
struct FImpl<TOut, float>
{
static void InverseRescaleFunction(TOut *out, const float *in,
double intercept, double slope, size_t size)
{
....
}
};
-M