new keywords for (C++)++

Discussion in 'C++' started by Gernot Frisch, Jun 15, 2005.

  1. When someone thinks about a new version of C++, how about including
    these:

    -----------------------
    typeof:
    class A
    {
    public:
    void foo();
    } a;

    typefo(a) b;
    b.foo();

    -----------------------
    typeofbase:

    class A
    {
    public:
    foo();
    };

    class B : public A
    {
    foo() {typeofbase::foo();} // calls: A::foo();
    };




    --
    -Gernot
    int main(int argc, char** argv) {printf
    ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
    Gernot Frisch, Jun 15, 2005
    #1
    1. Advertising

  2. On Wed, 15 Jun 2005 11:41:06 +0200, "Gernot Frisch" <>
    wrote:

    >When someone thinks about a new version of C++, how about including
    >these:


    [snip]

    comp.std.c++ is the place to ask this question.

    --
    Bob Hairgrove
    Bob Hairgrove, Jun 15, 2005
    #2
    1. Advertising

  3. Gernot Frisch

    Pete Becker Guest

    Gernot Frisch wrote:
    > When someone thinks about a new version of C++, how about including
    > these:
    >


    As Bob Hairgrove said, clc++ is the place for this. But a suggestion:
    instead of proposing keywords, talk about what problem you're trying to
    solve. Syntax comes later.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
    Pete Becker, Jun 15, 2005
    #3
  4. Gernot Frisch

    Howard Guest

    "Gernot Frisch" <> wrote in message
    news:...
    > When someone thinks about a new version of C++, how about including these:
    >
    > -----------------------
    > typeof:
    > class A
    > {
    > public:
    > void foo();
    > } a;
    >
    > typefo(a) b;
    > b.foo();
    >
    > -----------------------
    > typeofbase:
    >
    > class A
    > {
    > public:
    > foo();
    > };
    >
    > class B : public A
    > {
    > foo() {typeofbase::foo();} // calls: A::foo();
    > };
    >
    >
    >
    >
    > --
    > -Gernot
    > int main(int argc, char** argv) {printf


    Why would you need that? Can't you just look and see the type you want? It
    looks like all you're saving is some effort on your part to know what you're
    doing. It's not like you suddenly want a new type for b because you're
    changing the type of a, or that your base class simply changes at some
    point. Such changes would generally involve how you use the objects, not
    just their type. Do you have a real-world problem that this solves?

    -Howard
    Howard, Jun 15, 2005
    #4
  5. Gernot Frisch

    Arkadiy Guest

    Howard wrote:

    > Why would you need that? Can't you just look and see the type you want? It
    > looks like all you're saving is some effort on your part to know what you're
    > doing. It's not like you suddenly want a new type for b because you're
    > changing the type of a, or that your base class simply changes at some
    > point. Such changes would generally involve how you use the objects, not
    > just their type. Do you have a real-world problem that this solves?


    Here are a couple of examples where typeof/decltype/auto would be
    useful:

    1)

    #include <boost/lambda/lambda.hpp>
    using namespace boost::lambda;

    auto var = 15 < _1 && _1 < 20;

    (the type is too complicated to specify by hand)

    2)

    template<class T, class U>
    typeof(T() + U()) add(T t, U u)
    {
    return t + u;
    }

    (it's impossible to specify the type by hand)

    A library-based implementation of typeof has been recently accepted
    into Boost and will most likely become available as a part of Boost
    starting version 1.34. See
    http://boost-sandbox.sourceforge.net/vault/, typeof.zip for the current
    version.

    Regards,
    Arkadiy
    Arkadiy, Jun 16, 2005
    #5
  6. Arkadiy wrote:
    > Howard wrote:
    >
    >
    >>Why would you need that? [...]

    >
    >
    > Here are a couple of examples where typeof/decltype/auto would be
    > useful: [...]


    To put your discussion to end, there is a proposal to introduce the
    keyword 'decltype' and reuse 'auto' for those purposes. See N1607:
    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1607.pdf

    I am surprised that you kept posting about those, the proposal has been
    around for quite a while. Perhaps you should just go to the Standard
    Committee site (http://www.open-std.org/jtc1/sc22/wg21/) and peruse it
    for some time before arguing again... :)

    V
    Victor Bazarov, Jun 16, 2005
    #6
  7. Gernot Frisch

    Arkadiy Guest

    Howard wrote:

    > Why would you need that? Can't you just look and see the type you want? It
    > looks like all you're saving is some effort on your part to know what you're
    > doing. It's not like you suddenly want a new type for b because you're
    > changing the type of a, or that your base class simply changes at some
    > point. Such changes would generally involve how you use the objects, not
    > just their type. Do you have a real-world problem that this solves?


    Here are a couple of examples where typeof/decltype/auto would be
    useful:

    1)

    #include <boost/lambda/lambda.hpp>
    using namespace boost::lambda;

    auto var = 15 < _1 && _1 < 20;

    (the type is too complicated to specify by hand)

    2)

    template<class T, class U>
    typeof(T() + U()) add(T t, U u)
    {
    return t + u;
    }

    (it's impossible to specify the type by hand)

    A library-based implementation of typeof has been recently accepted
    into Boost and will most likely become available as a part of Boost
    starting version 1.34. See
    http://boost-sandbox.sourceforge.net/vault/, typeof.zip for the current
    version.

    Regards,
    Arkadiy
    Arkadiy, Jun 16, 2005
    #7
  8. Gernot Frisch

    Arkadiy Guest

    Well, if you like you can wait until this proposal is accepted, and
    then until the compiler vendors implement it...

    Or you can have something that works right now (see the Boost sandbox
    file vault).

    Regards,
    Arkadiy
    Arkadiy, Jun 16, 2005
    #8
  9. Arkadiy wrote:
    > Well, if you like you can wait until this proposal is accepted, and
    > then until the compiler vendors implement it...
    >
    > Or you can have something that works right now (see the Boost sandbox
    > file vault).


    I am not sure I understand. Works right now how? You're proposing new
    keywords to be added to the language, no? Without actually adding them
    (and that's the job for compiler implementors) how is "something" going
    to satisfy your need for new keywords?

    V
    Victor Bazarov, Jun 16, 2005
    #9
  10. Gernot Frisch

    Pete Becker Guest

    Victor Bazarov wrote:
    > Arkadiy wrote:
    >
    >> Well, if you like you can wait until this proposal is accepted, and
    >> then until the compiler vendors implement it...
    >>
    >> Or you can have something that works right now (see the Boost sandbox
    >> file vault).

    >
    >
    > I am not sure I understand. Works right now how? You're proposing new
    > keywords to be added to the language, no? Without actually adding them
    > (and that's the job for compiler implementors) how is "something" going
    > to satisfy your need for new keywords?
    >


    And, of course, this raises the complementary question: if there's
    something that works right now, why is a new keyword needed?

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
    Pete Becker, Jun 16, 2005
    #10
  11. Gernot Frisch

    Arkadiy Guest

    I am not proposing new keywords added -- other people are, and I do
    agree with them.

    However, the process of implementing language changes is quite lengthy.
    OTOH, the feature is so useful that one can benefit even from the
    limited solution a library can implement.

    In our case the limitation is that one has to "tell" the library about
    user-defined types/templates by "registering" them, something like:

    BOOST_TYPEOF_REGISTER_TYPE(foo)
    BOOST_TYPEOF_REGISTER_TEMPLATE(bar, 2) // 2 template parameters

    After this is done any combination of registered types/templates can be
    handled, in case of my earlier lambda example:

    BOOST_AUTO(x, 15 < _1 && _1 < 20); /* equivalent to: auto x = 15 < _1
    && _1 < 20; */

    Regards,
    Arkadiy
    Arkadiy, Jun 16, 2005
    #11
  12. Gernot Frisch

    Arkadiy Guest

    Because a library-based solution has limitations that can't be avoided.

    Regards,
    Arkadiy
    Arkadiy, Jun 16, 2005
    #12
    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. Bruce
    Replies:
    0
    Views:
    690
    Bruce
    Aug 13, 2004
  2. valentin tihomirov

    Advantages of denying keywords as identifiers

    valentin tihomirov, Dec 17, 2004, in forum: VHDL
    Replies:
    8
    Views:
    511
    Mike Treseler
    Dec 28, 2004
  3. dw

    Friend & Protected keywords

    dw, May 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,853
  4. hari4063

    New keywords

    hari4063, Feb 5, 2004, in forum: C++
    Replies:
    1
    Views:
    429
    AirPete
    Feb 5, 2004
  5. Replies:
    2
    Views:
    450
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page