From -8263979851758092020
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,782fb3724018b13e
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-05-18 00:45:01 PST
Path: archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!skynet.be!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Paul Mensonides" <pmenso57@home.com>
Newsgroups: comp.std.c++
Subject: Re: All I want for Christmas (was C++0x)
Date: Fri, 18 May 2001 07:44:51 GMT
Organization: Excite@Home - The Leader in Broadband http://home.com/faster
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <153N6.24719$p33.428418@news1.sttls1.wa.home.com>
References: <LvnL6.9938$la.137783@news1.sttls1.wa.home.com> <9dpnro$j7ajt$1@ID-14036.news.dfncis.de>
X-Trace: mail2news.demon.co.uk 990171898 mail2news:20481 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-Mimeole: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Date: Thu, 17 May 2001 23:14:21 PDT
Lines: 74
Xref: archiver1.sj.google.com comp.std.c++:4940

Hey, Andrei, what do you think of some type of templated parameter list?  For
example...

template<class T> class SomeCollection {
    private:
        unsigned m_size;
        T* m_v;
    public:
        template<class U, V(...)> void for_each(U (T::* pm)(V), V) {
            for (int i = 0; i < m_size; ++i) {
                m_v[i].*pm(#V); // #V indicates values rather than type
            }
        }
};

Which, for a given call:

class MyClass {
    public:
        void get(int, int);
};

void f() {
    SomeCollection<MyClass> x;
    //populate x...
    x.for_each(&MyClass:get, 0, 0); // possible disambiguation of &MyClass::get,
maybe: &MyClass::get(int, int) ?
}

where for_each expands to: // allowing type "void" to be used as a return type

    void SomeCollection<MyClass>::for_each(void (MyClass::* pm)(int, int), int
unnamed_1, int unnamed_2) {
        for (int i = 0; i < m_size; ++i) {
            m_v[i].*pm(unnamed_1, unnamed_2);
        }
    }

My example may be going for the most-convoluted award, but the idea anyway could
be a good one.  Transparent use of templated parameter lists.  I think this
would make some types of generic programming significantly easier.  (I'll delay
a further tirade about the semantics of overloading operator->*() for
pointer-to-member-function types and how annoying that is.)

What do you think?
Thanks for the book, by the way.  It was an eye-opener! :)
(Unfortunately, all that I have to use right now is VC++ :( , so most of it
won't compile.)

Paul Mensonides

| By the way, if I had my way, I'd have "if" on compile-time constants not
| compile the branch that's guaranteed not to execute. Kind of like template
| functions that are not instantiated unless used. That would simplify a lot
| of generic code - now I have to use Int2Type all the time.

Agreed, that is annoying in one-or-the-other-but-not-both situations...

template<class X, bool T> void f() {
    X* x = 0;
    if (T) {
        x = new X(0);
    }
    else {
        x = new X;
    }
}

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]



