c++ - Functional programming with boost: pass a boost::bind to a boost::bind -
I'm writing to try to get a functional approach for some code. Want to pass in another function that does something with it, and then to schedule a later function at a I inspired the definition of ( But I'm getting: candidates After a big list of And if you can not use c ++ 11, then you can use the function template as a multicolor Functions can be converted into objects: and use it (to avoid mixing the bind to See this Print: boost :: asio :: io_service .
io_service :: post )
template
#include & lt; Stdio.h & gt; # Include & lt; Boost / asio / io_service.hpp & gt; # Include & lt; Boost / bind.hpp & gt; Template & lt; Typename FUNC & gt; Zero foo_then_smile (FUNC handler) {handler (); Printf ("smile \ n!"); } Zero foo (int a, int b, int c) {printf ("important answer is% d \ n", a + b + c); } Int main () {boost :: asio :: io_service ioService; IoService.post (boost :: bind (foo_then_smile, boost :: bind (foo, 1, 2, 3))); Return 0; }
to call "bind (& lt; unsolved loaded type type & gt ;, :: : BI :: bind_t & lt; Void, void (*) (int, int, int), boost :: _ bi :: list3 & quot; boost :: _ bi :: value & gt; int & gt; boost :: _ bi :: value & lt; int & gt;, boost: _ bi:: value
struct foo_then_smile {typedef void result_type; Template & lt; Typename FUNC & gt; Zero operator () (FUNC handler) const {handler ()); Printf ("smile \ n!"); }};
protect to note ): < Pre>
IoService.post (boost :: bind (foo_then_smile), boost :: security (boost :: tie (foo, 1, 2, 3))));
#include & lt; Stdio.h & gt; # Include & lt; Boost / asio / io_service.hpp & gt; # Include & lt; Boost / bind.hpp & gt; #include & lt; Boost / bind / protect.hpp & gt; Struct foo_then_smile {typedef zero result_type; Template & lt; Typename FUNC & gt; Zero operator () (FUNC handler) const {handler ()); Printf ("smile \ n!"); }}; Zero foo (int a, int b, int c) {printf ("important answer is% d \ n", a + b + c); } Int main () {boost :: asio :: io_service ioService; IoService.post (boost :: tie (foo_then_smile), boost :: security (boost :: tie (foo, 1, 2, 3))); IoService.run (); }
Important answer 6 smile!
Comments
Post a Comment