473,394 Members | 1,746 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,394 software developers and data experts.

Can this be solved with templates?

Hello, I wrote a simple class that can measure the time it takes to
call a function using some platform dependent code. The actual
measurement function in this timer class has this signature:

typedef void (*FunctionPointer)(const long double *, const long double
*, std::size_t);

double TimerClass::time_function(FunctionPointer fptr, const long
double *x, const long double *y, std::size_t size)

The arguments following the function pointer is those that are to be
sent to the function that is measured...so this class is not reusable
at all, it only works for functions taking those arguments...can I do
some template magic here be able to use it with all functions, no
matter their argument lists? Or maybe something else?

- Eric

Apr 29 '07 #1
2 1183
On 29 Apr, 22:07, Eric Lilja <mindcoo...@gmail.comwrote:
Hello, I wrote a simple class that can measure the time it takes to
call a function using some platform dependent code. The actual
measurement function in this timer class has this signature:

typedef void (*FunctionPointer)(const long double *, const long double
*, std::size_t);

double TimerClass::time_function(FunctionPointer fptr, const long
double *x, const long double *y, std::size_t size)

The arguments following the function pointer is those that are to be
sent to the function that is measured...so this class is not reusable
at all, it only works for functions taking those arguments...can I do
some template magic here be able to use it with all functions, no
matter their argument lists? Or maybe something else?
you could use boost::function/bind library

template<class F>
double time_function(F f)
{
// your timing here
f();
}

// 0 arity
void fun();
time_function(&fun);

// 1 arity
void fun1(int);
// time call fun1(5)
time_function(boost::bind(&fun, 5));

// member function
struct A
{
void fun();
void fun1(int);
};

A a;
// time call a.fun()
time_function(boost::bind(&A::fun, &a));

// time call a.fun1(5)
time_function(boost::bind(&A::fun, &a, 5));

D.

Apr 30 '07 #2
On 30 Apr, 10:53, dasjotre <dasjo...@googlemail.comwrote:
// time call a.fun1(5)
time_function(boost::bind(&A::fun, &a, 5));
that should be
time_function(boost::bind(&A::fun1, &a, 5));


Apr 30 '07 #3

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

Similar topics

1
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The...
3
by: Erhard Schwenk | last post by:
Hi there, Maybe this is a faq, if so, point me the URL please. I have to do some xml to xml transformations in xslt, where I have - simplified - the following: input: <doc>...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
0
by: Luther Hert | last post by:
I solved my problem, but I am not sure whether or not I understand how I arrived at the solution. I leraned about and checked: IIS> creating virtual directories> configuring web extensions >...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.