|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi,
can a non-type argument of a template be of float type? If no, how can one get same intended result? rds, |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Hicham Mouline a écrit :
> hi, > can a non-type argument of a template be of float type? no. > If no, how can one get same intended result? I don't know the result you want ![]() If you want to parametrize a type with a float value, then you cannot unless you wrap it in a parametrized class. template<int ID> struct ParamFloat; template<> struct ParamFloat<0> { static const float value=0.0; }; template<> struct ParamFloat<1> { static const float value=3.14116; }; //... Then struct<class FLOAT> struct mult2 { static float value=FLOAT::value*2f; }; If you want to use or compute a float value (computing series ...) then you just embed the value: template<unsigned N> struct slow_pi { static const double value= sqrt2<N-1>::value + ((N%2)?1.0:-1.0)/(2N+1); }; template<> struct slow_pi<0> { static const double value =1; }; Michael |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Hicham Mouline wrote:
> can a non-type argument of a template be of float type? > If no, how can one get same intended result? I haven't used this, but it looks like the right idea: http://mi.eng.cam.ac.uk/~er258/code/fp_template.html |
|
![]() |
| Outils de la discussion | |
|
|