floating point template parameters (called specialization?)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: floating point template parameters (called specialization?)

  1. #1
    Join Date
    Dec 2010
    Posts
    599

    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

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,879

    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.

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,721

    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

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,721

    Re: floating point template parameters (called specialization?)

    Erased (Duplicate)
    "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

  5. #5
    Join Date
    Dec 2010
    Posts
    599

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center