473,405 Members | 2,404 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,405 software developers and data experts.

How to divide typenames from a function declaration?

HI,
Pls. see the following function declaration:
int foo(const char *);

How to get the return typename and parameter typenames from the declaration?
For example, I need some codes like the following pseudocode:

typedef typename ReturnType(&foo)::Type AType;

Regards,
Leo Liu
Jul 19 '05 #1
1 1872
Blace Ice wrote:
HI,
Pls. see the following function declaration:
int foo(const char *);

How to get the return typename and parameter typenames from the declaration?
For example, I need some codes like the following pseudocode:

typedef typename ReturnType(&foo)::Type AType;


Check out this example. I think it will do what you're asking.

This compiled with gcc 3.3.1 and did what I expected.
#include <iostream>

template <typename T>
class FuncParam
{
public:

enum { is_func = 0 };

typedef int t_ret;
typedef int t_val;
};
// only works for single parameter functions.

//
// specialize for a single parameter function.
// w_ret FUNC( w_val )
//
template <typename w_ret, typename w_val>
class FuncParam<w_ret ( w_val )>
{
public:
enum { is_func = 1 };

typedef w_ret t_ret;
typedef w_val t_val;
};
typedef char * TYPE( short & );

typedef char OTYPE;
std::ostream & PrintMe( std::string s )
{
return std::cout << s << "\n";
}

template <typename T>
typename FuncParam<T>::t_ret Somthing(
T * func,
typename FuncParam<T>::t_val v
) {
return func( v );
}
int main()
{

std::cout << FuncParam<TYPE>::is_func << "\n";

Somthing( PrintMe, "TRY THIS" ) << " AND THIS\n";
}

Jul 19 '05 #2

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

Similar topics

9
by: Anthony Heading | last post by:
Hi all, I've often found myself wanting to write code like the example here. Since both MSVC and gcc both reject it, I suspect it is indeed illegal. gcc: no type named `Name' in `class...
20
by: Christian Christmann | last post by:
Hi, in a benchmark I've found an uncommon use of a function. This is the simplified form: 1 int foo( int f ) 2 { 3 return f; 4 } 5
20
by: svata | last post by:
Hello there, after some time of pondering I come to some solution which would suit me best. Please correct, if I am wrong. Function has two parameters. A string array, better said a pointer to...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
40
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
5
by: td0g03 | last post by:
Here is the question....Write a statement that declares a prototype for a function divide that takes four arguments and returns no value. The first two arguments are of type int . The last two...
12
by: rajm2019 | last post by:
Without using /,% and * operators. write a function to divide a number by 3. itoa() function is available
4
by: Adam Nielsen | last post by:
Hi everyone, I've having some trouble trying to specialise a template. My original code, with one typename, worked: template <typename T> class MyClass { private: T data;
1
by: jrhitokiri | last post by:
there is something wrong with my code. I was doing some homework trying to implement the "divide" function recursively in JS but it gives some wrong results. here's my code: it returns the...
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: 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
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
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.