Questions tagged [boost-bind]

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions.

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions. bind does not place any requirements on the function object; in particular, it does not need the result_type, first_argument_type and second_argument_type standard typedefs.

boost::bind was proposed for standardization and a version of it was included in as std::tr1::bind and an improved version is included in the standard as std::bind (see ).

352 questions
3
votes
1 answer

Error using boost::bind for subscribe callback

We're getting this compile error followed by many more errors showing attempts to match the subscribe parameters to all possible candidate functions when using boost::bind as a callback for subscribe. error: no matching function for call to…
Sagar Mohan
  • 145
  • 1
  • 5
  • 17
3
votes
1 answer

std::stringstream as parameter to a function

I have a std::vector temp_results and I wish to use std::for_each to go through this vector and concatenate a string, so I concocted the following construction: std::stringstream ss; std::string res = std::for_each(temp_results.begin(),…
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
3
votes
1 answer

Use of boost coroutine2 without lambdas

I guess this is the first time I couldn't manage to find an already answered question in here, and I could really use some help if anyone have successfully used boost coroutine2 lib without lambdas. My problem, sumarized: class worker { ... void…
Marcio Mutti
  • 33
  • 1
  • 4
3
votes
2 answers

boost::bind doesn't work with pointer argument

I have this simple program. Here I try to bind member function with object and call later on with arguments required in member function call. When the member function taken a pointer to integer, gcc fails to compile. With integer parameter the…
mivi
  • 348
  • 5
  • 8
3
votes
3 answers

C++ - binding function

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…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
3
votes
4 answers

Boost::asio and boost::bind: Functor memory is never released

My code is allocating memory and never freeing it, even though it should (at least in my opinion). The header looks like this: typedef boost::asio::ssl::stream sslSocket_t; class Object { boost::asio::io_service…
Norman
  • 73
  • 7
3
votes
1 answer

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(B&)> object. I prefer not to create an ad-hoc function boost::shared_ptr foo(B& b) { return boost::shared_ptr(new A(b)); } to solve my problem,…
fbasile
  • 273
  • 3
  • 9
3
votes
1 answer

How to properly use a class member function with boost::coroutine?

I'm currently working with boost::asymmetric_coroutine. Let's say we have an ordinary function in the global namespace: void foo(boost::coroutines::asymmetric_coroutine::push_type & sink) { //do something sink(100); //do something…
SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
3
votes
2 answers

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 …
Kyle
  • 4,487
  • 3
  • 29
  • 45
3
votes
1 answer

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

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…
srossi
  • 122
  • 1
  • 6
3
votes
3 answers

binding to member variables

The following example from boost bind does not work for me: #include 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 =…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
3
votes
1 answer

boost::program_option::store throws exception when option string contains mixed language characters

I have simple code that works perfectly well with input option contains just ASCII characters, but throws an exception with error message of "error: character conversion failed". Is there a solution? Background info: 1. Compiler and OS: VC++2012…
James
  • 31
  • 2
3
votes
1 answer

Partial binding with boost::bind

so what I have is: Two ranges of elements: std::vector v1; std::vector v2; Function that accept elements from theese ranges: void bar( int x, std::string str ); And what I wanna do is to apply handler to each pair from product of v1…
prez
  • 603
  • 5
  • 7
3
votes
2 answers

boost::bind thread for pointer to function with argument

I have a function foo(myclass* ob) and I am trying to create a consumer thread using consumer_thread(boost::bind(&foo)(&ob)) The code does not compile which I believe is due to my inappropriate way of passing the function argument to the function…
ND_27
  • 764
  • 3
  • 8
  • 26
3
votes
2 answers

How can I search a container of objects for a data member value?

I have an object type like this: struct T { int x; bool y; }; and a container of them like this: std::vector v; and a burning desire to determine — in a single statement — whether any of the elements of v have y == true. This likely…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055