-
September 12th, 2012, 12:57 AM
#1
floating point template parameters (called specialization?)
This code snippet just won't compile in a conforming compiler:
Code:
template<> struct series<0.0, 0, 0>
because of the floating point template parameter....
If this "specialization" is useful, how come MS would have discarded it?
Thanks
Jack
-
September 12th, 2012, 03:04 AM
#2
Re: floating point template parameters (called specialization?)
The C++ standard specifies that there are restrictions on what a non-type template parameter can be, and double isn't one of them.
It can be:
An integer type or enum constant/literal value
the name of a non-type template-parameter
the address of a function or object with external linkage
a pointer to member
You 'sort of' can make double values with a bit of rule bending.
You could either pass an integer parameter and use it as a double with a fixed scale. Suppose you wanted a double with at most 3 decimal positions, then you would pass an integer where integer/1000 is the double value you want.
You could pass 2 integers: a Divident and a divisor where the quotient is the desired double (so the double template parameter is divident / divisor).
The drawback is that it may not help for all template needs. And not all double values can be accurately enough be described by an X/Y type expression.
-
September 12th, 2012, 03:21 AM
#3
Re: floating point template parameters (called specialization?)
the address of a function or object with external linkage
a pointer to member
Interesting. I wasn't aware of those last two.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 12th, 2012, 03:28 AM
#4
Re: floating point template parameters (called specialization?)
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 12th, 2012, 03:43 AM
#5
Re: floating point template parameters (called specialization?)
If I want to pass 0.001 i would pass 1, for example?
Then inside the function, I do 1/1000 to retrieve back the value I am after....
Okay, fair enough
Thanks a lot, have a nice day
Jack
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|