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
2
votes
2 answers

Memory leak using multiple boost::connect on single slot_type

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…
Chris O'Bryan
  • 496
  • 6
  • 9
2
votes
1 answer

Boost undefined reference error with boost::bind overloaded operators

The code in question: boost::function isSpecialWeapon = boost::bind(&WeaponBase::GetType,this) == WeaponType::SPECIAL_WEAPON; The error I get is something like so: undefined reference to `boost::_bi::bind_t
dchhetri
  • 6,926
  • 4
  • 43
  • 56
2
votes
1 answer

C++:BOOST-bind error: no matching function for call to 'bind(, ...?

I tried to turn this boost-asio server into a class and I got this one error trying to compile it, C:\Documents and Settings\tcpip_server\TCPIP_server.h||In member function 'void TCPIP_server::server(boost::asio::io_service&, short…
pandoragami
  • 5,387
  • 15
  • 68
  • 116
2
votes
2 answers

How to copy with member access using boost

I have a container of As with struct A { int f(); } The container offers iterators and we can for this example assume it's an std::vector. So: std::vector As; Now I want to copy the values provided by A::f into a second…
Gabriel Schreiber
  • 2,166
  • 1
  • 20
  • 33
2
votes
2 answers

Passing function pointer arguments with boost

Can the following function pointer passing be simplified/improved with the use of boost::function and/or boost::bind? void PassPtr(int (*pt2Func)(float, std::string, std::string)) { int result = (*pt2Func)(12, "a", "b"); // call using function…
pingu
  • 8,719
  • 12
  • 50
  • 84
2
votes
1 answer

Nesting a tr1::bind<> object from tr1::bind() in a new call to tr1::bind()

I'm a little confused why this call to bind doesn't work. I've narrowed the problem down to trying to nest a bind object in a new call to bind. #include #include #include using namespace std; using…
NHDaly
  • 7,390
  • 4
  • 40
  • 45
2
votes
2 answers

boost::bind with member functions (as boost::asio async write handler)

I'm using boost::bind to pass a handler function to boost::asio::async_write. When I use free functions, it works fine, but when I try to move the functions inside a class, bind produces errors that I am unable to decipher. What works: I write some…
Riot
  • 15,723
  • 4
  • 60
  • 67
2
votes
3 answers

C++11: return_type (for std::bind) of functor where return type is based on input type

I'm playing with functor composition, where the return type of a functor depends on the input type: template class F { protected: V v_; public: using return_type = ?; F(V v) : v_(v) {} template typename…
bruno nery
  • 2,022
  • 2
  • 20
  • 31
2
votes
1 answer

How to safely destruct Posix thread pool in C++

I am trying to implement thread pool in C++ using pthread. I want to encapsulate logic related to threads management in one object which is taking ownership of these threads. That means whenever this object is destroyed, threads must be stopped and…
Marcin
  • 279
  • 1
  • 4
  • 13
2
votes
1 answer

boost::bind together with boost::asio. boost::bind not working, copied from an example

Could someone tell me why this does not compile? I basically copied it from an example by Kholkoff (http://lists.boost.org/Archives/boost/2007/04/120339.php), back in 2007, about reads() in sockets with timeouts: void…
deinocheirus
  • 1,833
  • 5
  • 26
  • 44
2
votes
1 answer

What is wrong with this boost::lambda::bind usage?

Is there something wrong in this code? I keep getting compilation errors. Basically I want to connect a void returning function to a signal which has a non void return type. Boost version: Release 1.46.1 #include #include…
Sak
  • 269
  • 1
  • 4
  • 13
2
votes
3 answers

binding an assignment operator to a boost::function object

I have a Visual Studio 2008 C++03 project where I would like to use a boost::function object to set the value of a pointer. Something like this: boost::function< void( int* ) > SetValue; boost::function< int*() > GetValue; int* my_value_; SetValue…
PaulH
  • 7,759
  • 8
  • 66
  • 143
2
votes
1 answer

how do I compose multiple functors using boost bind?

I've got a situation where I have a series of member functions which produce simple information on a target object: double MyDoc::GetX(thing) double MyDoc::GetY(thing) etc. I've made some "pretty formatting" member functions in the same…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
2
votes
2 answers

How do I use boost::signals to implement the observer pattern?

I have an application consisting of many linked objects, each of which have parameters that they need in order to function. I am using the context pattern so that each object sets its own parameters according to a context object reference that is…
learnvst
  • 15,455
  • 16
  • 74
  • 121
1
vote
1 answer

Boost.Bind non-static member

I have the following code, in which Boost.Local uses a function callback to load a mo file. The function is called findMo for me, and I'm trying to bind it to an object so I can retain the side effects I put in private members of moFinder. class…
Jookia
  • 6,544
  • 13
  • 50
  • 60