473,807 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#define and commas

I am using a macro to define template functions that look the same
except for a type. However when the return type it a template class
with several template arguments (say, A<T1, T2>) then the macro does
not work because of the comma -- the macro thinks there are more
arguments provided since the comma separates arguments. To avoid the
comma being taken into account the usual way is to put parenthesis,
but here it would not work because the argument is a return type, and
I cannot declare a function like

(A<T1, T2>) foo();

Is there a way to get around this problem?

Thanks

B.
Jul 22 '05 #1
3 6118
Bolin wrote:
I am using a macro to define template functions that look the same
except for a type. However when the return type it a template class
with several template arguments (say, A<T1, T2>) then the macro does
not work because of the comma -- the macro thinks there are more
arguments provided since the comma separates arguments. To avoid the
comma being taken into account the usual way is to put parenthesis,
but here it would not work because the argument is a return type, and
I cannot declare a function like

(A<T1, T2>) foo();

Is there a way to get around this problem?


So, you have something like

#define MYFUNC(T) A<T> foo##T(T t) { A<T> tt(t); return tt }

and want to use it to define a function with more than one template
argument? I guess I don't understand. Post more code.

Alternative: define a different macro for more than one argument:

#define MYFUNC1(T) ...
#define MYFUNC2(T,U) ...

and so on.

V
Jul 22 '05 #2
Bolin wrote:
I am using a macro to define template functions that look the same
except for a type. However when the return type it a template class
with several template arguments (say, A<T1, T2>) then the macro does
not work because of the comma -- the macro thinks there are more
arguments provided since the comma separates arguments. To avoid the
comma being taken into account the usual way is to put parenthesis,
but here it would not work because the argument is a return type, and
I cannot declare a function like

(A<T1, T2>) foo();

Is there a way to get around this problem?


The only way of fixing this is to declare multiple macros, one for each
number of commands in the input.

The is fixed in C99 with variable length macros, for example by:

#define DEBUGLIST(...) fprintf(stderr, __VA_ARGS__)

While this isn't in C++ yet, some compilers (in particular g++) will let
you use this C99 construct in C++ code, and I would be highly suprised
if it doesn't end up appearing in the very next version of C++.
Chris
Jul 22 '05 #3

"Bolin" <ga*******@voil a.fr> wrote in message
news:93******** *************** **@posting.goog le.com...
I am using a macro to define template functions that look the same
except for a type. However when the return type it a template class
with several template arguments (say, A<T1, T2>) then the macro does
not work because of the comma -- the macro thinks there are more
arguments provided since the comma separates arguments. To avoid the
comma being taken into account the usual way is to put parenthesis,
but here it would not work because the argument is a return type, and
I cannot declare a function like

(A<T1, T2>) foo();

Is there a way to get around this problem?

Thanks

B.


None that springs to mind. But the usual way to define functions (templates
or not) that look the same except for a type is to use a template. So
perhaps if you post the macro someone could suggest a way to make a template
from it.

john
Jul 22 '05 #4

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

Similar topics

22
13789
by: ineedyourluvin1 | last post by:
Hello all! I've been looking for a way to strip characters from strings such as a comma. This would be great for using a comma as a delimiter. I show you what I have right now. #include<iostream> #include<string> int main(int argc, char *argv) {
7
8321
by: AES | last post by:
Encountered a URL containing a comma the other day -- the first time I've ever noticed that, so far as I can recall. It worked fine, however, and I gather commas are legal in URLs. Out of curiosity, did a quick scan of an ASCII file of the 542 URLs in my personal bookmark file and discovered exactly 3 that contained commas (two with a single comma, one with three commas) -- so I guess they're pretty rarely used, even if legal. Seems...
27
2065
by: Peter Ammon | last post by:
My code obfuscator gave me this: char buff; to which gcc retorted: "ISO C90 forbids variable-size array 'buff'" and checking the standard, it appears that commas are indeed forbidden from being in a constant expression.
3
7633
by: Robert Scheer | last post by:
Hi. I have a regularexpression validator control on a page. This regular expression validates a textbox to accept only numbers and commas: validationexpression="*" I am trying to modify this expression to not allow commas at the beginning and at the end of the expression without success. It needs to allow commas only between the numbers. How can I do that?
4
2491
by: striker | last post by:
I have a comma delimited text file that has multiple instances of multiple commas. Each file will contain approximatley 300 lines. For example: one, two, three,,,,four,five,,,,six one, two, three,four,,,,,,,,,,eighteen, and so on. There is one time when multiple commas are allowed. Just prior to the letters ADMNSRC there should be one instance of 4 commas. ( ,eight,,,,ADMNSRC,thirteen, ). The text ADMNSRC is NOT in the same
5
4017
by: hprYeV | last post by:
I have done a reasonable amount of programming in C++, but the other day I was talking to someone after a lecture in a course on Java who said that they had not been used to the syntax of the Java for loop because they always had been programming in C++. I asked them what it was they had not been used to, and they said that in C++ you can use commas to separate the initial statement, the condition, and the loop statement like this: ...
9
8891
by: conspireagainst | last post by:
I'm having quite a time with this particular problem: I have users that enter tag words as form input, let's say for a photo or a topic of discussion. They are allowed to delimit tags with spaces and commas, and can use quotes to encapsulate multiple words. An example: tag1, tag2 tag3, "tag4 tag4, tag4" tag5, "tag6 tag6" So, as we can see here anything is allowed, but the problem is that splitting on commas obviously destroys tag4...
23
3925
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
11
10497
by: Dooza | last post by:
Using ASP/VB I need to remove unwanted commas from the end of a field that will be use in an array. There are items in the field that are comma separated, so I don't want to remove them, just the end ones, could be anywhere up to 5 unwanted commas. Any ideas? Cheers, Steve
0
9599
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
10626
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...
0
10372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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
10112
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
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
3854
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.