boost-function

Getting return value from a boost::threaded member function?

荒凉一梦 提交于 2019-11-29 04:29:18
I have a worker class like the one below: class Worker{ public: int Do(){ int ret = 100; // do stuff return ret; } } It's intended to be executed with boost::thread and boost::bind, like: Worker worker; boost::function<int()> th_func = boost::bind(&Worker::Do, &worker); boost::thread th(th_func); th.join(); My question is, how do I get the return value of Worker::Do? Thanks in advance. I don't think you can get the return value. Instead, you can store the value as a member of Worker: class Worker{ public: void Do(){ int ret = 100; // do stuff m_ReturnValue = ret; } int m_ReturnValue; } And use

Pass and call a member function (boost::bind / boost::function?)

萝らか妹 提交于 2019-11-28 00:58:13
问题 I have a probably embarassingly simple problem: pass and call a member function in a class. I know I want to use BOOST bind (and or function), but I haven't really grasped the concept to it yet. The following code compiles and executes with problem. But when I want to change the "f3" function to a non-static class function, then the fun begins: #include <iostream> #include <inttypes.h> #include <boost/bind.hpp> #include <boost/function.hpp> class Test { public: void f1(); private: void f2

Getting return value from a boost::threaded member function?

不羁的心 提交于 2019-11-27 18:21:11
问题 I have a worker class like the one below: class Worker{ public: int Do(){ int ret = 100; // do stuff return ret; } } It's intended to be executed with boost::thread and boost::bind, like: Worker worker; boost::function<int()> th_func = boost::bind(&Worker::Do, &worker); boost::thread th(th_func); th.join(); My question is, how do I get the return value of Worker::Do? Thanks in advance. 回答1: I don't think you can get the return value. Instead, you can store the value as a member of Worker:

Performance of std::function compared to raw function pointer and void* this?

邮差的信 提交于 2019-11-27 05:56:15
问题 Library code: class Resource { public: typedef void (*func_sig)(int, char, double, void*); //Registration registerCallback(void* app_obj, func_sig func) { _app_obj = app_obj; _func = func; } //Calling when the time comes void call_app_code() { _func(231,'a',432.4234,app_obj); } //Other useful methods private: void* app_obj; func_sig _func; //Other members }; Application Code: class App { public: void callme(int, char, double); //other functions, members; }; void callHelper(int i, char c,

How to use boost bind with a member function

本小妞迷上赌 提交于 2019-11-26 17:21:32
The following code causes cl.exe to crash (MS VS2005). I am trying to use boost bind to create a function to a calls a method of myclass: #include "stdafx.h" #include <boost/function.hpp> #include <boost/bind.hpp> #include <functional> class myclass { public: void fun1() { printf("fun1()\n"); } void fun2(int i) { printf("fun2(%d)\n", i); } void testit() { boost::function<void ()> f1( boost::bind( &myclass::fun1, this ) ); boost::function<void (int)> f2( boost::bind( &myclass::fun2, this ) ); //fails f1(); f2(111); } }; int main(int argc, char* argv[]) { myclass mc; mc.testit(); return 0; }

how boost::function and boost::bind work

耗尽温柔 提交于 2019-11-26 07:53:09
问题 I dislike having magic boxes scattered all over my code...how exactly do these two classes work to allow basically any function to be mapped to a function object even if the function<> has a completely different parameter set to the one im passing to boost::bind It even works with different calling conventions (i.e. member methods are __thiscall under VC, but \"normal\" functions are generally __cdecl or __stdcall for those that need to be compatible with C. 回答1: boost::function allows

How to use boost bind with a member function

回眸只為那壹抹淺笑 提交于 2019-11-26 05:24:10
问题 The following code causes cl.exe to crash (MS VS2005). I am trying to use boost bind to create a function to a calls a method of myclass: #include \"stdafx.h\" #include <boost/function.hpp> #include <boost/bind.hpp> #include <functional> class myclass { public: void fun1() { printf(\"fun1()\\n\"); } void fun2(int i) { printf(\"fun2(%d)\\n\", i); } void testit() { boost::function<void ()> f1( boost::bind( &myclass::fun1, this ) ); boost::function<void (int)> f2( boost::bind( &myclass::fun2,