Calling different C functions according to the C++ template type -


my problem following: have c library contain several versions of each function according data type working e.g.:

void add(double *a, double *b, double *c); 

and

void sadd(float *a, float *b, float *c); 

now, having external c++ template function, able like:

template<class t> void myfunc(/*params*/) {  // obtain a,b,c of type t* params  /*  if t double call add(a,b,c);  else if t float call sadd(a,b,c). */  } 

i aware can done specialized template functions like:

template<> void myfunc<double>(/*params*/) {   // obtain a,b,c of type double* params   add(a,b,c); } 

and on, not option since whole point of introducing templated c++ function reduce code repetition , "// obtain a,b,c of type t* params" part can long.

does problem have simple solution?

thanks

zdenek

define overloaded c++ forwarders:

inline void forward_add(double *a, double *b, double *c) { add( a, b, c ); } inline void forward_add(float *a, float *b, float *c) { sadd( a, b, c ); }  template<class t> void myfunc(/*params*/) {    // obtain a,b,c of type t* params    forward_add( a, b, c ); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -