Topic: Closures II (and other ideas)
Author: Valentin Bonnard <bonnard@clipper.ens.fr>
Date: 1999/02/15 Raw View
[I haven't followed this thread form the very beginning so maybe
this has already been discussed.]
With the STL, C++ programs look like functionnal programs.
However, w/o implicit closures, one has to create a class
and bring in all the context he wants explicitly:
struct T {
int& i;
float& f;
T (int&, flaot&);
int operator() () { /* use i, f */ }
};
int i;
float f;
foo (T (i, f));
when I would like to write
int i;
float f;
foo (lambda_or_something () { /* use i, f */ } )
Another related thing I would like to do:
Derived* f (Base*);
Base* (*pf) (Derived*) = &f;
Note that there is a big difference here: lambda_or_something ()
was of type SomeClass, just like T () above, but here pf is
of pointer type !
Also I can easilly live w/o the pointer to function cast, but
the implicit closure is much more important for me.
[ And before someone says that the pointer to function cast
is unimplementable w/o automatic code generation: it has already
been explained several times here that it can be implemented.]
And finally, I would like to be able to write:
struct Base {
virtual void foo (Derived*);
};
struct Derived : Base {
void foo (Base*) overrides Base::foo (Derived*);
};
with the often proposed override keyword.
See also:
http://www.eleves.ens.fr:8080/home/bonnard/evol/lambda.html
http://www.eleves.ens.fr:8080/home/bonnard/evol/override.html
--
Valentin Bonnard
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]