boost-function

Boost::Bind and virtual function overloads: why do they work?

谁说我不能喝 提交于 2019-12-18 21:15:11
问题 I wrote some code and got scared that it will not work - so I wrote a prototype: #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class base { private: boost::function<void (int)> action; protected: virtual void onDataBaseReady(int i) { std::cout << i << std::endl; } public: void call() { action(10); } base() { action = boost::bind(&base::onDataBaseReady, this, _1); } }; class child : public base { protected: virtual void onDataBaseReady(int i) { std::cout << i+10 <

Boost::Bind and virtual function overloads: why do they work?

拥有回忆 提交于 2019-12-18 21:13:46
问题 I wrote some code and got scared that it will not work - so I wrote a prototype: #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class base { private: boost::function<void (int)> action; protected: virtual void onDataBaseReady(int i) { std::cout << i << std::endl; } public: void call() { action(10); } base() { action = boost::bind(&base::onDataBaseReady, this, _1); } }; class child : public base { protected: virtual void onDataBaseReady(int i) { std::cout << i+10 <

boost::bind & boost::function with partial args

风流意气都作罢 提交于 2019-12-14 00:40:55
问题 I post you an example of what I want to do, that is easier to explain in this way void myPrinter(const char* text, int number){ printf("\n%s %d\n", text, number); } int main() { char *someText="test"; boost::function<void(int my_number)> functionWithSavedArgs = boost::bind(&myPrinter, someText, ?????); //then I have to call my function with saved args and give to it only variable "number" like: int myBeautifulNumber = 2012; functionWithSavedArgs(myBeautifulNumber); // echo: test 2012 } Any

Boost.Lambda - dereference placeholder

无人久伴 提交于 2019-12-13 04:07:01
问题 Is there a way to dereference a placeholder inside lambda expression ? boost::function<int(MyClass*)> f = _1->myMethod(); f(myObject); I know I can make a binding: boost::function<int(MyClass*)> f = boost::bind(&MyClass::myMethod, _1); , but I want to build more complex expression, with if statements and so on. 回答1: In theory this should work: struct Foo { int bla() { return 2; } }; boost::function<int(Foo*)> func = (_1 ->* &Foo::bla); There is an old discussion featuring various work-arounds

Help with boost bind/functions

淺唱寂寞╮ 提交于 2019-12-11 05:17:31
问题 I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target sig Here's what I have so far: //somewhere else... ... registerFunction<LuaEngine>("testFunc", &LuaEngine::testFunc, this); ... //0 arg callback void funcCallback0(boost::function<void ()> func, lua_State *state) { func(); } template<typename SelfType> void registerFunction(const std::string &funcName, boost::function<void (SelfType*)> func, SelfType *self) { //funcToCall has to match lua

What is wrong with this boost::lambda::bind usage?

天涯浪子 提交于 2019-12-11 00:55:24
问题 Is there something wrong in this code? I keep getting compilation errors. Basically I want to connect a void returning function to a signal which has a non void return type. Boost version: Release 1.46.1 #include <boost/signals2.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> using namespace boost::signals2; void func() { printf("Func called!"); } main() { signal<int(int)> sig; sig.connect( (boost::lambda::bind(func), 1) ); } I get the following error while compiling:

Problem with boost::bind, boost::function and boost::factory

别来无恙 提交于 2019-12-10 21:25:56
问题 I'm trying without success to use a boost::bind with a boost::factory I have this class Zambas with 4 arguments (2 strings and 2 ints) and class Zambas { public: Zambas(const std::string&, const std::string&,int z1=0,int z2=0) { if (z1==z2){ } } }; inside other method i have the following call boost::function<Zambas*()> f(boost::bind(boost::factory<Zambas*>(), std::string(""), std::string(""),_1,_2)); that fails with the following compiler error: bind.hpp:382: error: no match for ‘operator[]’

boost bind class function pointer

半城伤御伤魂 提交于 2019-12-10 19:48:26
问题 class Foo { double f1( int x, std::string s1 ); double f2( int x, SomeClass s2 ); } I want to be able to bind Foo.f1's s1 without an instance of foo to create in essense typedef double (Foo::* MyFooFunc)( int ) MyFooFunc func1 = boost::bind( &Foo::f1, _1, _2, "some string" ); MyFooFunc func2 = boost::bind( &Foo::f2, _1, _2, SomeClass ); Then I pass func1 and func2 as parameters to other functions, inside which Foo is finally bound: void SomeOtherFunction( MyFooFunc func ) { Foo foo; boost:

boost::bind & boost::function with partial args

 ̄綄美尐妖づ 提交于 2019-12-08 13:11:30
I post you an example of what I want to do, that is easier to explain in this way void myPrinter(const char* text, int number){ printf("\n%s %d\n", text, number); } int main() { char *someText="test"; boost::function<void(int my_number)> functionWithSavedArgs = boost::bind(&myPrinter, someText, ?????); //then I have to call my function with saved args and give to it only variable "number" like: int myBeautifulNumber = 2012; functionWithSavedArgs(myBeautifulNumber); // echo: test 2012 } Any ideas? Just skip that argument. boost::function<void(int my_number)> functionWithSavedArgs = boost::bind(

How to parse a mathematical expression with boost::spirit and bind it to a function

こ雲淡風輕ζ 提交于 2019-12-05 04:28:50
问题 I would like to define a function taking 2 arguments double func(double t, double x); where the actual implementation is read from an external text file. For example, specifying in the text file function = x*t; the function should implement the multiplication between x and t , so that it could be called at a later stage. I'm trying to parse the function using boost::spirit. But I do not know how to actually achieve it. Below, I created a simple function that implements the multiplication. I