473,976 Members | 6,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1894
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
2416
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 Collection<Animal>' msvc7: error C2039: 'Name' : is not a member of 'Collection<Traits>' But to me it seems pretty unambiguous, so I can't see why it's wrong. Could anybody give me a pointer, either to the standard or the basic
20
2395
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
1830
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 it, char *p_buf and int size. int read_name( char *p_buf, int size) { char *p_item_name_1;
2
5360
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: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
40
3719
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 int) ? Same question for the corresponding unsigned types.
5
8624
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 arguments arguments are pointers to int that are set by the function to the quotient and remainder of dividing the first argument by the second argument. The function does not return a value. Here is my code void divide(int , int, pInt* quotient,...
12
7090
by: rajm2019 | last post by:
Without using /,% and * operators. write a function to divide a number by 3. itoa() function is available
4
1965
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
2227
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 quotient and remainder. function Divide(x,y) { var result1; if (x == 0) return ; result = Divide(Math.floor(x/2),y);
0
10352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10171
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11818
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11571
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10083
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5153
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.