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
7
votes
1 answer

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 Help understanding boost::bind placeholder arguments : #include #include struct X { int…
Marc Andreson
  • 3,405
  • 5
  • 35
  • 51
7
votes
1 answer

Passing a unique_ptr reference to boost::bind?

I'm on CentOS 6.6 (gcc 4.4.7) and developing with Boost.Asio (1.41). I'd like io_service to call member function run() in manger object m when it starts. The code I'm trying to compile looks like: #include #include #include…
7
votes
4 answers

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…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
7
votes
3 answers

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

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,…
jdt141
  • 4,993
  • 6
  • 35
  • 36
7
votes
1 answer

How do I utilize boost::packaged_task, function parameters, and boost::asio::io_service?

First and foremost, I want to apologize for the lengthy post. I wanted to be as thorough as possible. I've been stuck on this issue for a few days now, and there is surprisingly little information regarding the proper use of boost::packaged_task on…
JohanBjorn
  • 71
  • 1
  • 3
7
votes
2 answers

Binding to a member variable

I am confused as to what boost::bind does when we bind to member variables. With binding to member function, we essentially create a function object, and then call it passing to it the arguments that are provided or delayed and substituted via…
navigator
  • 1,588
  • 1
  • 13
  • 19
6
votes
1 answer

Does boost::bind() copy parameters by reference or by value?

Why does valgrind's DRD tool complaines "Conflicting load by thread ... at size 4": about such code: void SomeFunction(const int& value) { boost::bind(..., value); /* <-- complaines on this line with last…
Slaus
  • 2,086
  • 4
  • 26
  • 41
6
votes
4 answers

Delete raw pointer argument to boost::bind

Lets say I have heap allocated A*, which I want to pass as argument to boost::bind. boost::bind is saved for later processing in some STL like container of boost::functions's. I want to ensure A* will be destroyed at destruction of the STL…
dimba
  • 26,717
  • 34
  • 141
  • 196
6
votes
2 answers

Pass and call a member function (boost::bind / boost::function?)

I have a probably embarassingly simple problem: pass and call a member function in a class. I know I want to use BOOST bind (and or function), but I haven't really grasped the concept to it yet. The following code compiles and executes with problem.…
BaCh
  • 625
  • 2
  • 5
  • 17
6
votes
1 answer

What is the difference between boost::bind and boost::lambda::bind?

I can see that there are two different bind libraries for Boost, one "standalone", that can be used by including boost/bind.hpp, and another by including boost/lambda/bind.hpp. What's the difference between these two?
petersohn
  • 11,292
  • 13
  • 61
  • 98
6
votes
2 answers

How can I use boost::bind to bind a class member function?

#include #include #include class button { public: boost::function onClick; boost::function onClick2; }; class player { public: void play(int…
codebeing
  • 127
  • 2
  • 11
6
votes
1 answer

boost bind compilation error

class A { bool OutofRange(string& a, string& b, string c); void Get(vector & str, string& a, string& b); } void A::Get(vector & str, string& a, string& b) { str.erase( std::remove_if (str.begin(), str.end(),…
aajkaltak
  • 1,437
  • 4
  • 20
  • 28
6
votes
2 answers

C ++ Boost Bind Performance

Are there any performance impacts (positive or negative) when binding functions (using Boost Bind) ?
tropicana
  • 1,403
  • 2
  • 19
  • 27
5
votes
2 answers

Does copying a boost::function also copy the closure?

Say I have a function like this: void someFunction(const ExpensiveObjectToCopy&); If I make a boost::function out if it, that function will store its own cloned copy of the object in its closure: boost::function f =…
Chris
  • 6,642
  • 7
  • 42
  • 55
5
votes
3 answers

Using boost::bind() across C code, will it work?

Can I use boost::bind(mycallback, this, _1, _2) across C code? Update The short answer is no, boost bind does not return a function pointer, which can be called in C code, but a functor (C++ object with overloaded () operator) see answer below.
unixman83
  • 9,421
  • 10
  • 68
  • 102
1 2
3
23 24