generic solution to functions that differ only by 'f' (float) and 'd' (double)

Discussion in 'C++' started by ma740988, Apr 8, 2006.

  1. ma740988

    ma740988 Guest

    Given:
    void mxvmvd(double *pv1, long ninc1, double *pso, long n);
    void mxvmvf( float *pv1, long ninc1, float *pso, long n);

    How would I write a generic solution (template version) that'll call
    the appropriate function based on the float or double type?
    I've got vendor API's that has two separate functions that differ only
    by 'f' (float) or 'd' (double). My intent is to put a wrappers around
    these functions. I tempted to do a typeid 'check' but I'm unsure if
    that's necessary/is the right approach.

    Thanks in advance.
    ma740988, Apr 8, 2006
    #1
    1. Advertising

  2. ma740988

    Phlip Guest

    ma740988 wrote:

    > void mxvmvd(double *pv1, long ninc1, double *pso, long n);
    > void mxvmvf( float *pv1, long ninc1, float *pso, long n);
    >
    > How would I write a generic solution (template version) that'll call
    > the appropriate function based on the float or double type?
    > I've got vendor API's that has two separate functions that differ only
    > by 'f' (float) or 'd' (double). My intent is to put a wrappers around
    > these functions. I tempted to do a typeid 'check' but I'm unsure if
    > that's necessary/is the right approach.


    You could use a template, but all you need is an overload:

    void mxvmv(double *pv1, long ninc1, double *pso, long n)
    { mxvmvd(pv1, ninc1, pso, n); }
    void mxvmv( float *pv1, long ninc1, float *pso, long n);
    { mxvmvd(pv1, ninc1, pso, n); }

    You are looking at a C-style overload, so the simplest wrapper is a real C++
    overload.

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
    Phlip, Apr 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,452
    Victor Bazarov
    Feb 17, 2005
  2. bd
    Replies:
    0
    Views:
    605
  3. Michael Gross
    Replies:
    0
    Views:
    614
    Michael Gross
    Jul 30, 2003
  4. Colin Paul Gloster
    Replies:
    0
    Views:
    660
    Colin Paul Gloster
    Jan 11, 2007
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,505
    James Kanze
    Oct 8, 2009
Loading...

Share This Page