boost-bind

Access boost::function arguments

Is it possible to access the arguments contained in a boost::function type? I'd like to be able to retrieve the address of the function to be called, and the values of the arguments provided for that function. ...

boost::bind accessors?

Suppose I have the following code: int f(int, int); int main() { SomeFunc(boost::bind(f, 1, 2)); } From the SomeFunc() function, is it possible to access the arguments held by the bound type? Something like this (pseudo code): // Obvious syntax issues... void SomeFunc(boost::bind& functor) { if(functor.function == &f) {...

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

sort using boost::bind

bool pred(int k, int l, int num1, int num2) { return (num1 < num2); } int main() { vector <int> nums; for (int i=50; i > 0; --i) { nums.push_back(i); } std::sort (nums.begin(), nums.end(), boost::bind(&pred, 5, 45)); } I am a boost newbie. I was learning to use boost::bind and I wanted to sort a vector of intege...

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 bind compilation error

class A { bool OutofRange(string& a, string& b, string c); void Get(vector <string>& str, string& a, string& b); } void A::Get(vector <string>& str, string& a, string& b) { str.erase( std::remove_if (str.begin(), str.end(), BOOST_BIND(&A::OutOfRange, a, b, _1)), str.end() ); } I am getting ...

Memory leak using multiple boost::connect on single slot_type

Hi, I'm using boost::signals and leaking memory when I try to connect multiple signals to a single slot_type. I've seen this same leak reported on various forums, but can't find any that mention the correct way to do this, or any workaround. What I am trying to do: I am trying to pass the result of boost::bind() into a function. In th...

C++: how to use std::less<int> with boost::bind and boost::lambda?

I am trying to lean boost::bind, boost::lambda libraries and how they can be used with STL algorithms. Suppose I have vector of int-string pairs which is sorted by int key. Then a place to insert a new pair while keeping the vector sorted can be found as follows: std::vector<std::pair<int, string> > entries; ... int k = ...; // Let's i...

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

boost::bind with null function pointers

If the function pointer embedded in a boost::bind return object is NULL/nullptr/0, I need to take action other than calling it. How can I determine if the object contains a null function pointer? Addenda I don't believe I can use and compare boost::functions as the boost::bind return object is used with varying call signatures in a te...

removing strings from a vector via boost::bind

I am trying to remove short strings from a vector. std::vector<std::string> vec; // ... vec.erase(std::remove_if(vec.begin(), vec.end(), boost::bind(std::less<size_t>(), boost::bind(&std::string::length, _1), 5),...

Distinguish between const and non-const method with same name in boost::bind

When I use boost::bind with a method name which is declared both const and non-const I am getting in ambiguous error, for example boost::bind( &boost::optional<T>::get, _1 ) How can I solve this problem? ...

binding to member variables

The following example from boost bind does not work for me: #include <boost/bind.hpp> struct A { int data; }; int main() { A a; boost::bind(&A::data, _1)(a) = 1; } error: assignment of read-only location 'boost::bind [with A1 = boost::arg<1>, M = int, T = A](&A::data, (<unnamed>::_1, boost::arg<1>())).boost::_bi::bind_t<...

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

Using for_each and boost::bind with a vector of pointers

I have a vector of pointers. I would like to call a function for every element, but that function takes a reference. Is there a simple way to dereference the elements? Example: MyClass::ReferenceFn( Element & e ) { ... } MyClass::PointerFn( Element * e ) { ... } MyClass::Function() { std::vector< Element * > elements; // add...

Macro to improve callback registration readability

I'm trying to write a macro to make a specific usage of callbacks in C++ easier. All my callbacks are member functions and will take this as first argument and a second one whose type inherits from a common base class. The usual way to go is: register_callback(boost::bind(&my_class::member_function, this, _1)); I'd love to write: re...

How to implement generic callbacks in C++

Forgive my ignorance in asking this basic question but I've become so used to using Python where this sort of thing is trivial that I've completely forgotten how I would attempt this in C++. I want to be able to pass a callback to a function that performs a slow process in the background, and have it called later when the process is com...

boost::binding that which is already bound

I have a Visual Studio 2008 C++ application that does something like this: template< typename Fcn > inline void Bar( Fcn fcn ) // line 84 { fcn(); }; template< typename Fcn > inline void Foo( Fcn fcn ) { // this works fine Bar( fcn ); // this fails to compile boost::bind( Bar, fcn )(); }; int main() { SYSTEM_...