Re: [GD-General] Eiffel
Brought to you by:
vexxed72
From: Thatcher U. <tu...@tu...> - 2001-12-21 15:06:12
|
On Dec 21, 2001 at 01:56 -0500, Kent Quirk wrote: > > fact, one of the things that I love about Java and wish that C++ had was > anonymous classes. They provide the only way to deal with the concept of > functors in generic algorithms where the functor is defined at the same > point as the algorithm is used. In C++ you can put it nearby. In Java > you can stick an anonymous class right inline. It's a powerful, useful, > and very general mechanism, similar to a lambda notation. Someone showed me this trick recently: ... struct Function { static void Call(int arg) { // some code. } } Instance; SomeFunctionTakingAFunctionPointer(Function::Call); ... For extra flexibility, define an interface class: struct Functor { virtual void Call(int arg); }; void SomeFunctionTakingAFunctor(Functor* f); ... struct HandleResults : public Functor { vector<int> results; void Call(int arg) { results.push_back(arg); } } Instance; // Call SomeFunction... and collect its results. SomeFunctionTakingAFunctor(&Instance); // Now Instance.results has the args passed to Instance.Call(). You can beef up HandleResults with a constructor and other members to parameterize stuff. I'm still sick of C++ though. The useful modern stuff I want to use is all a huge PITA. Templates stink, (lack of) introspection stinks, header files stink, manual memory management stinks, and pardon me, but IMHO the STL stinks as far as usability goes. -- Thatcher Ulrich <tu...@tu...> http://tulrich.com |