Nana provides a template like std::function called nana::functor, the library uses this template for convenience and agility. For example.
Code:void foo(); struct T { void foo(); }; nana::functor<void()> fn; fn = foo; fn(); //call foo; T t; fn = nana::make_fun(t, &T::foo); fn(); // call t.foo(); //it's convenient for event callback. button btn; btn.make_event<events::click>(foo); btn.make_event<events::click>(make_fun(t, &T::foo));
Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.
Originally Posted by manasij7479Its unary + operator could also be "appropriately" used to start the computer, and that doesn't mean that objects of that class are logically numeric in some way... once you begin abusing operator overloading, lots of strange names become appropriateOriginally Posted by manasij7479
The point is, a function object (functor) is logically a function. If you are overloading operator() for some other purpose, then you are not working with a function object, and we should start asking if the overloaded operator should have been given a more descriptive name, like... start.
EDIT:
In fact, overloading unary operator+ to start the computer is superior to overloading operator() because you can then overload unary operator- to mean shut down and operator~ to mean reboot!
Last edited by laserlight; 12-12-2011 at 03:27 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I don't exactly agree with you, but I must point out that you very nicely contradicted yourselfOriginally Posted by manasij7479
Refer to:
Originally Posted by manasij7479
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Generally speaking, if we provide a framework and accept the exterior defined actions. like this.
In fact, we don't care whether fn is a function or function object, also don't care what fn does. And the user who calls for_each() should give a function or a object which can be applyed through function-call syntax.Code:template<typename Iterator, typename Functor> Functor for_each(Iterator beg, Iterator end, Functor fn) { for(Iterator i = beg; i != end; ++i) fn(*i); return fn; }
Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.
The biggest difference between that and Qt's signals and slots system is that in S&S, the object generating the event doesn't need to explicitly call callbacks. The meta objects system does that for the programmer.
All the programmer needs to do is bind slots to signals, and then, when the signal is fired, all connected slots will automatically be "called" (the observer pattern according to Wikipedia).
It avoids having to write a callback functions that just calls a bunch of other callback functions. In the case of Qt, the "callback functions" (slots) can also be (and usually are) member functions, which makes designs simpler.
That's true.
I'm just trying to justify the use of moc in Qt (because I'm a big fan of it).
This library also claims to make programming more intuitive and OO by not using macros, etc. But Qt says it uses moc exactly to make it more OO and intuitive.
So the discussion now is on whether the library discussed here has achieved the goal.