Template Stringizing-How should it work?

Discussion in 'C++' started by Steven T. Hatton, Sep 10, 2004.

  1. 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.
     
    Steven T. Hatton, Sep 10, 2004
    #1
    1. Advertising

  2. Steven T. Hatton

    Jeff Flinn Guest

    "Steven T. Hatton" <> wrote in message
    news:...
    > 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
     
    Jeff Flinn, Sep 10, 2004
    #2
    1. Advertising

  3. Jeff Flinn wrote:

    >
    > "Steven T. Hatton" <> wrote in message
    > news:...
    >> 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.
     
    Steven T. Hatton, Sep 10, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    syntax of stringizing macro

    Siemel Naran, Nov 6, 2004, in forum: C++
    Replies:
    8
    Views:
    1,889
    Old Wolf
    Nov 9, 2004
  2. Henry Townsend

    stringizing a hex value in the preprocessor

    Henry Townsend, Dec 2, 2005, in forum: C Programming
    Replies:
    14
    Views:
    796
  3. Ravi

    Stringizing

    Ravi, Nov 1, 2006, in forum: C Programming
    Replies:
    1
    Views:
    383
    Arthur J. O'Dwyer
    Nov 1, 2006
  4. Peter Nilsson
    Replies:
    1
    Views:
    480
    James Antill
    Jun 27, 2007
  5. Replies:
    2
    Views:
    383
Loading...

Share This Page