boost-bind

How to use/manipulate return value from nested boost::bind

I have two functions: 1. A & DataSource(); 2. void DataConsumer( A * ); What I want to achieve: Using one statement to assemble them into one functor. I have tried: 1. boost::function< void()> func( boost::bind( DataConsumer, & boost::bind( DataSource ) ) ); certainly it didn't work, compiler says it can not convert 'boost::_bi::bind...

Adapting Map Iterators Using STL/Boost/Lambdas

Consider the following non-working code: typedef map<int, unsigned> mymap; mymap m; for( int i = 1; i < 5; ++i ) m[i] = i; // 'remove' all elements from map where .second < 3 remove_if(m.begin(), m.end(), bind2nd(less<int>(), 3)); I'm trying to remove elements from this map where .second < 3. This obviously isn't written correctl...

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

Copy vector of values to vector of pairs in one line

I have the following types: struct X { int x; X( int val ) : x(val) {} }; struct X2 { int x2; X2() : x2() {} }; typedef std::pair<X, X2> pair_t; typedef std::vector<pair_t> pairs_vec_t; typedef std::vector<X> X_vec_t; I need to initialize instance of pairs_vec_t with values from X_vec_t. I use the following code and it ...

boost lambda::bind return type selection

I would like to call a member through lambda::bind. Unfortunately I have got two members with the same name but different return types. Is there a way to help the lambda::bind to deduce the right return type for a member function call? (bind works fine with explicit return type deduction) #include <vector> #include <iostream> #include <...

boost doesn't bind to member function even using this

Hi all I am trying to use boost::bind with a boost::function using this. It seems a trivial example but I cannot make it work.Can you help me? Is it because it is not allowed or am I doing something wrong? Thanks afg // .h class MyClass{ publc: void DoSomething( const std::string& a, const std::string& b); vo...

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

Binding a member signal to a function

This line of code compiles correctly without a problem: boost::bind(boost::ref(connected_), boost::dynamic_pointer_cast<session<version> >(shared_from_this()), boost::asio::placeholders::error); However when assigning it to a boost::function or as a callback like this: socket_->async_connect(connection_->r...

c++ generic pointer to (member?) function

I can't seem to declare a generic pointer to function. Having these 2 functions to be called: void myfunc1(std::string str) { std::cout << str << std::endl; } struct X { void f(std::string str){ std::cout<< str << std::endl;} }; and these two function callers: typedef void (*userhandler_t) (std::string); struct example {...

C++ question: boost::bind receive other boost::bind

I want to make this code work properly, what should I do? giving this error on the last line. what am I doing wrong? i know boost::bind need a type but i'm not getting. help class A { public: template <class Handle> void bindA(Handle h) { h(1, 2); } }; class B { public: void bindB(int number, in...

boost::bind breaks strict-aliasing rules?

Using Boost 1.43 and GCC 4.4.3, the following code boost::bind(&SomeObject::memberFunc, this, _1)); Generates the following warning boost/function/function_base.hpp:321: warning: dereferencing type-punned pointer will break strict-aliasing rules What's the correct way to eliminate these warnings without setting -fno-strict...

Problem with boost::bind

The following code throws an error at the line where I want to create a functor object of Test::fun2: #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> using namespace boost; class Test { public: float fun1() { return 0.0f; } void fun2( float x ) {} }; int main( int argc, char* argv[] ) { s...

boost bind template error

//error C2784: 'HRESULT get_wrapper(T *,boost::function<R(void)>)' : //could not deduce template argument for 'boost::function<R(void)>' //from 'boost::_bi::bind_t<R,F,L>' STDMETHODIMP CAttributeValue::get_Name(BSTR* pVal) { return get_wrapper(pVal, boost::bind<BSTR>(&CAttributeValue::getNameCOM, this)); //error here } template <...

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

boost shared_from_this<>()

Hello all, could someone summarize in a few succinct words how the boost shared_from_this<>() smart pointer should be used, particularly from the perspective of registering handlers in the io_service using the bind function. EDIT: Some of the responses have asked for more context. Basically, I'm looking for "gotchas", counter-intuitive ...

Using boost::bind and boost::lambda::new_ptr to return a shared_ptr constructor

Given a class A, class A { public: A(B&) {} }; I need a boost::function<boost::shared_ptr<A>(B&)> object. I prefer not to create an ad-hoc function boost::shared_ptr<A> foo(B& b) { return boost::shared_ptr<A>(new A(b)); } to solve my problem, and I'm trying to solve it binding lambda::new_ptr. boost::function<boost::shared_p...

Boost.Bind - understanding placeholders

I am trying to understand the following example, that is similar (but not equal) to the one posted earlier on the SO http://stackoverflow.com/questions/2120725/help-understanding-boostbind-placeholder-arguments : #include <boost/bind.hpp> #include <functional> struct X { int value; }; int main() { X a = { 1 }; X b = {...

How to call a member function on a parameter with std::for_each and boost::bind?

I want to add a series of strings to a combo box using std::for_each. The objects are of type Category and I need to call GetName on them. How can I achieve this with boost::bind? const std::vector<Category> &categories = /**/; std::for_each(categories.begin(), categories.end(), boost::bind(&CComboBox::AddString, &comboBox, _1); The c...

Using a boost signal within boost::bind.

I'm trying to wrap triggering for a boost::signal into a boost::bind object. So what I want is to invoke the signal with some pre-packaged arguments when the boost::function is called. What I have is this: boost::signals2::signal<void(int)> sig; boost::function<void()> f = boost::bind( &(sig.operator()), &sig, 10); But this doesn...

C++ - binding function

Hello! I have some (library API, so I can't change the function prototype) function which is written the following way: void FreeContext(Context c); Now, at some moment of my execution I have Context* local_context; variable and this is also not a subject to change. I wish to use boost::bind with FreeContext function, but I need to ...