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

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 "refactoring" (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,"Studebaker"> 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 1851

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:74********************@speakeasy.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******@setidava.kushan.aa> wrote in message
news:74********************@speakeasy.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
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++....
2
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...
31
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...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
10
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. ...
2
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. ...
1
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...
3
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...
9
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));...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.