473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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


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.

Apr 8 '06 #1
1 1574
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!!!
Apr 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Newton | last post by:
hi all, i'm relatively new to python. I find it a pretty interesting language but also somewhat limiting compared to lisp. I notice that the language does provide a few lispy type nicities, but...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
14
by: Michael Sgier | last post by:
Hello If someone could explain the code below to me would be great. // return angle between two vectors const float inline Angle(const CVector& normal) const { return acosf(*this % normal); }...
13
by: agentxx04 | last post by:
Hi. Our assignment was to creat a program that can find the average, median & mode of a #of integers. Here's my program: #include<stdio.h> int main() { int item; int a, b, t, mode; int...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
7
by: Kamran | last post by:
Hi, I have hundreds of variables inside a class (integer, float) and a long range of set/get functions to manipulate their values. What I am wondering about is whether there is a way in C++ to...
7
by: vabby | last post by:
Hi I have run into an eerie situation whihc i cant make out. I have a class A which has has two virtual functions with the same name, having diff arguments. Basically a case of function...
2
by: PengYu.UT | last post by:
Hi, I'm wondering if there are any template trigonometry functions in C++. I used the following code for that purpose. But if the library has it, it will be better. Thanks, Peng #include...
7
by: juerg.lemke | last post by:
Hi everyone I am interested in having multiple functions with different prototypes and deciding, by setting a pointer, which of them to use later in the program. Eg: int f1(void); char*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.