Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template non-type arguments

Reply
Thread Tools

template non-type arguments

 
 
Hicham Mouline
Guest
Posts: n/a
 
      02-27-2008
hi,
can a non-type argument of a template be of float type?
If no, how can one get same intended result?
rds,


 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      02-27-2008
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
 
Reply With Quote
 
 
 
 
Jeff Schwab
Guest
Posts: n/a
 
      02-27-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template template arguments and default parameters avasilev C++ 2 10-06-2011 01:40 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Design issue : "self type" as a default template argument (recursive template arguments) IR C++ 3 11-22-2006 08:38 PM
problem calling method from parent of an object if object relayson template arguments of current template class? =?UTF-8?B?UmFmYcWCIE1haiBSYWYyNTY=?= C++ 2 03-02-2006 05:45 AM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM



Advertisments