boost-function

Error C2228 when constructing boost::function object in constructor argument list

The code below does not compile in Visual C++ 2005. class SomeClass { public: boost::function<void()> func; SomeClass(boost::function<void()> &func): func(func) { } }; void someFunc() { std::cout << "someFunc" << std::endl; } int main() { SomeClass sc(boost::function<void()>(&someFunc)); sc.func(); // error C2228: ...

C++ Functors and Zero

Hello all: First a disclaimer, I am replacing a bunch of code which uses boost::function and boost::bind. However, I am moving to a codebase which does not allow rtti. I would like to keep using boost but don't know if there is a way around this restriction. So..., I am trying to mimic some of its functionality, but much more simplif...

Help with boost bind/functions

Hi, 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)...

"corrupted double-linked list" on boost::function free()

I am going to try to ask this question without supplying too much source code because all the relevant bits add up to a bunch. The key (I think?) objects involved are using namespace o2scl; typedef MSMTModel<TASensor,PosModel,target2d,ovector,ovector_const_subvector> TA_MSMTModel; typedef MPC_funct_mfptr<MSMT_InitialState,TA_MSMTModel...

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

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 quest...

boost::function run-time performance

I'm in the process of implementing a platform independent wrapper for dynamically loaded libraries. Of course when I load functions from the libraries I need to store them as pointers for future use. I thought of using boost::function's for that instead of normal function pointers. Sure, that will increase compile time, but that's not wh...

STL algorithms on containers of boost::function objects

I have the following code that uses a for loop and I would like to use transform, or at least for_each instead, but I can't see how. typedef std::list<boost::function<void(void) > CallbackList; CallbackList callbacks_; //... for(OptionsMap::const_iterator itr = options.begin(); itr != options.end(); ++itr) { callbacks_.push_back(boo...

Class member function as callback using boost::bind and boost::function

Hey all - I'm working through setting up a member function as a callback for a C-library that I'm using. The C-library sets up callbacks like this: typedef int (*functionPointer_t)(myType1_t*, myType2_t*, myType3_t*); setCallback(param1, param2, functionPointer, param4) I would like to use boost::bind (if possible) to pass in the fu...

What is wrong with this boost::lambda use?

Why is this boost::lambda expression not working? boost::function<bool (boost::uint64_t, boost::uint64_t&, unsigned int, float)> myFunct = boost::lambda::_3 < 1; I get theses compilation errors, that won't probably help, because they are really cryptic. || In file included from /usr/include/boost/function/detail/maybe_include.hpp:33,...

C++ virtual function call versus boost::function call speedwise

Hello, I wanted to know how fast is a single-inheritance virtual function call when compared to one same boost::function call. Are they almost the same in performance or is boost::function slower? I'm aware that performance may vary from case to case, but, as a general rule, which is faster, and to a how large degree is that so? Thank...

unresolved external symbol "public: void __thiscall..."

I'm using boost::function to enable the passing of a function to a Button constructor so it holds that function. Calling it whenever it is activated. typedef boost::function< void() > Action; In my TitleState I've constructed a Button like this. m_play( ButtonAction, // This is where I pass a function to Button's Action argume...

How to use boost bind with a member function

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) {...

How to force template function overload for boost::bind?

Hi, I'm trying to create predicate for std::find_if by using boost::bind together with boost::contains (from boost/algoritm/string library). Following snippet shows two ways how I'm trying to accomplish this. #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> #include <s...

Default value for boost::function argument?

I've got a function that I want to take an optional boost::function argument as a callback for reporting an error condition. Is there some special value I can use a the default value to make it optional? For example, with a regular function pointer I can do: void my_func(int a, int b, t_func_ptr err_callback=NULL) { if (error && (...

Making a function call performed from a static function, do something after return

This is for the purpose of a client/server program. The client asks for some data off the server, and receives it. Upon receiving this data from a Boost socket on the client side, I handle this message in a static method called parse_message in a class called client_protocol. This method, given this specific data, will start a process o...

How to use boost::bind with non-copyable params, for example boost::promise ?

Some C++ objects have no copy constructor, but have move constructor. For example, boost::promise. How can I bind those objects using their move constructors ? #include <boost/thread.hpp> void fullfil_1(boost::promise<int>& prom, int x) { prom.set_value(x); } boost::function<void()> get_functor() { // boost::promise is not copyab...

boost::function and plain function pointers: ambigous overload

Given the following member function overload to take various functors class Foo { public: void bar(boost::function<void(int)> func); void bar(boost::function<void(float)> func); void bar(boost::function<void(const std::vector<float>&)> func); } and the function void baz(float f) { std::cout << "float :" << f << st...

std::tr1::function::target<TFuncPtr> and co-/contravariance

Since I love progamming in both C# and C++, I'm about to implementing a C#-like event system as a solid base for my planned C++ SFML-GUI. This is only an excerpt of my code and I hope this clarifies my concept: // Event.h // STL headers: #include <functional> #include <type_traits> #include <iostream> // boost headers: #include <boost/...

C++ Boost function comparison

Hi, I have a class which contains boost::function as one of its arguments. I have to make this class equality comparable but the boost::function is not equality comparable. Is there a easy workaround for this problem? Thanks, Gokul. ...

Pointers to functions

Hello, I have to pass function into pointer. For this purposes I'm using boost::function. The function which catches the pointer is overloaded for different signatures. For example: void Foo(boost::function<int ()>) { ... } void Foo(boost::function<float ()>) { ... } void Foo(boost::function<double ()>) { ... } Now I wanna pass some c...