473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template Stringizing-How should it work?

I'm serious about this folks! I really want to see the CPP obviated.
People who have never used tools such as JBuilder may not fully appreciate
the advantages they provide. This isn't about pointer safety, or making
sure you aren't blowing the bounds of an array. Imagine you could select a
namespace, enter a command with a new name as an argument, and your IDE
would rename every identifier qualified with that namespace to the new
name. Not only that, but it would fix every reference throughout the code
base so that it referred to the new namespace. The JBuilder creators call
that "refactorin g" (using packages rather than namespaces). It isn't what
I mean by the term "refactor". To me, that is only a minor proceedure
performed as part of refactoring. But that's not what I want to discuss.
I'm just using it as an example of the many different capabilities Java
IDEs have.

I sincerely believe the CPP is the biggest reason C++ IDEs can't do these
kind of things. I'll add the observation that, if it's hard to build a
tool to navigate and manipulate source code, it's probably hard for a
programmer to do the same. Stroustrup's suggested approach to doing away
with the CPP is to find ways to accomplish the things people use the CPP
for as easily in native C++. You guys probably think I ignore everything
you tell me you use the CPP for. Well, that isn't the case. And I use the
CPP directly or indirectly as much, or more than a lot of you do. See for
example: http://doc.trolltech.com/3.3/moc.html#moc

There are three different areas of use that I have been able to identify for
the CPP. 1) #inclusion, 2) conditional compilation 3) stringizing program
elements. Right now I want to talk about the third of these. I just
discovered that it is possible to pass the equivalent of a string literal
to a template like this:

ISO/IEC 14882 §14.3.2
[Note: A string literal (2.13.4) does not satisfy the requirements of any of
these categories and thus is not an
acceptable template-argument. [Example:
template<class T, char* p> class X {
// ...
X();
X(const char* q) { /* ... */ }
};
// error: string literal
as template-argument
X<int,"Studebak er"> x1;
char p[] = "Vivisectionist ";
// OK
X<int,p> x2;
--end example] --end note]

I know this doesn't provide what the macro(#) provides. But it may be a
place to start. Could templates be used for the same kinds of things you
currently used the CPP # parameter for? What would they have to provide?
I'm not looking for the most esoteric example you can invent. I'm asking
about something that would provide 90% coverage.

Here's my first thought. Pass the name of a class to a template, and have
it converted to some kind of inner class with string representations of the
member variables and member functions. That might be useful for stuff like
introspection.

--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations , but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.

Jul 22 '05 #1
2 1865

"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:74******** ************@sp eakeasy.net...
I'm serious about this folks! I really want to see the CPP obviated.
....
There are three different areas of use that I have been able to identify for the CPP. 1) #inclusion, 2) conditional compilation 3) stringizing program
elements.


I doubt life is this simple. Can you survey boost usage of PP (BOOSTPP
aside), and say that all uses of PP fall in these categories? Function
signature arity generation comes to mind.

Jeff F
Jul 22 '05 #2
Jeff Flinn wrote:

"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:74******** ************@sp eakeasy.net...
I'm serious about this folks! I really want to see the CPP obviated.


...
There are three different areas of use that I have been able to identify

for
the CPP. 1) #inclusion, 2) conditional compilation 3) stringizing program
elements.


I doubt life is this simple. Can you survey boost usage of PP (BOOSTPP
aside), and say that all uses of PP fall in these categories? Function
signature arity generation comes to mind.

Jeff F


It doesn't really matter if I did not cover all usage. I didn't intend that
list to be comprehensive. What I covered are the uses of the CPP that I see
most in code I read. If there are issues that remain, they should be
addressed as well. I suspect some of the uses for the CPP are simply way
of doingthings that /could/ be done, and done well within C++, but the
person writing the code didn't put forth the effort to find that better
solution.
--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations , but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.

Jul 22 '05 #3

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

Similar topics

14
1643
by: LRS Kumar | last post by:
The following code - from "C++ Templates: The Complete Guide" by Vandevoorde/Josuttis - seems to compile with Borland C++. However it fails to compile with other compilers - Comeau Online and g++. Any idea why? template<typename T> class Shell { public: template<int N> class In {
2
7933
by: Xenos | last post by:
The new version of GCC is out and in its list of changes, it talks about the C++ Standard's requirements for using the typename and template keywords to disambiguate dependent names. I'm use to seeing typename being used, but I've never seen template used for this purpose. I've studied there example for a long time, and still don't understand what situations call for the template keyword (and reading the standard, to me, is Greek). Can...
31
3486
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will return. I tried to write something like this: template <class Type1, class Type2, class Type3> Type3 findMin(Type1 x, Type2 y){ return (x < y) ? x : y;
11
3590
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
10
2088
by: Suki | last post by:
Hi, I'm writing a templated class, and i dont want to use the class otherthan for some predetermined types, say, int, double etc. This class has no meaning for typenames other than those few. ========================= template <class T> myClass {....} ;
2
2009
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. This makes it difficult to spot errors. For example, F4 to "jump to next error" just jumps ot the next "template assistance" message. And since there are hundreds of them, this is quite obnoxious. Can I disable these things? Why is MSVC...
1
2355
by: mathieu | last post by:
Hello there, I am playing around with template metaprograming: I am trying to redefines my own types. But I am facing a small issue, where I cannot describe the whole implementation in one single class. Instead I have to separate implementation for binary and ascii in two different classes as I don't know how to use the traits technique for constructors. Any pointers very welcome !
3
3748
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and thawed it out. I built a console app using Microsoft Visual C++ 6 (VC++) and it worked great. Only one line in the header file had to be commented out. I built a console app using Borland C++ Builder 5. The linker complained of references to...
9
3469
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535)); BOOST_STATIC_ASSERT((bin<1111>::value == 15)); BOOST_STATIC_ASSERT((bin<0>::value == 0)); BOOST_STATIC_ASSERT((bin<1010, 0011>::value == 163)); you can find my implementation at:
1
4459
by: matz2k | last post by:
I've got a big problem with the CSS layout which I've produced with Photoshop/Dreamweaver especially for my ebay auctions. This is what it looks like http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250542673235 As you can see it can only be seen partially , can anyone help me with this? As fas as I can tell ebay's Iframe is messing up my layput, or am I wrong? Thx! here is the css/html code
0
8234
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
8677
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
8620
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...
0
8474
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
4079
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
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.