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

C++ generic factory with multiple constructor signatures?

Has anyone ever combined the classic generic factory by Andrei Alexandrescu (page 208 of Chapter 8 in Modern C++ Design) with the 'multifunction' capabilities of Boost.TypeErasure? That is, the flexibility to have several creator function signatures…
4
votes
2 answers

How should I delete a child object from within a parent's slot? Possibly boost::asio specific

I have written a network server class that maintains a std::set of network clients. The network clients emit a signal to the network server on disconnect (via boost::bind). When a network client disconnects, the client instance needs to be…
kaliatech
  • 17,579
  • 5
  • 72
  • 84
4
votes
2 answers

Perform argument substitution on nested boost::bind without composition

Suppose I have a function which takes a nullary functor as an argument: void enqueue( boost::function & functor ); I have another function which takes an int and does something internally: void foo( int a); I would like to nest, but not…
tgoodhart
  • 3,111
  • 26
  • 37
4
votes
2 answers

Applying C++11 move semantics to bound functions

I have some existing C++98 code that makes use of boost::function and boost:bind for asynchronous callbacks. Some relevant simplified fragments of the code include: typedef boost::function
Miral
  • 12,637
  • 4
  • 53
  • 93
4
votes
1 answer

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
Brian
  • 2,511
  • 20
  • 26
4
votes
3 answers

Multithreading using the boost library

Wish to simultaneously call a function multiple times. I wish to use threads to call a function which will utilize the machines capability to the fullest. This is a 8 core machine, and my requirement is to use the machine cpu from 10% to 100% or…
gagneet
  • 35,729
  • 29
  • 78
  • 113
4
votes
3 answers

Adapting Map Iterators Using STL/Boost/Lambdas

Consider the following non-working code: typedef map 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(), 3)); I'm trying to…
John Dibling
  • 99,718
  • 31
  • 186
  • 324
4
votes
1 answer

Difference between std::bind and boost::bind with polymorphism

I have a derived class from which I bind a virtual function that I did not override in this class, so I'm hoping to call the one of the parent class. It works nice with boost (1.55), but if I switch to std::bind from C++11, it refuse to compile…
Kiroxas
  • 891
  • 10
  • 24
4
votes
1 answer

removing strings from a vector via boost::bind

I am trying to remove short strings from a vector. std::vector vec; // ... vec.erase(std::remove_if(vec.begin(), vec.end(), boost::bind(std::less(), …
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
4
votes
1 answer

How to register a signal handler as a class method?

Suppose I have a class A, with a public method void f(int sig). In constructor of A I added signal(SIGSEV, boost::bind(&A::f, this, _1)); This returns compilation error error : cannot convert `boost::_bi::bind_t
e271p314
  • 3,841
  • 7
  • 36
  • 61
4
votes
2 answers

Post callbacks to a task queue using boost::bind

Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2(). Everything is the same except that, when triggered, it needs to post it…
4
votes
2 answers

Functors vs. std::bind

Sometimes I tend to write functors, not for the sake of maintaining state between function calls, but because I want to capture some arguments that are shared between function calls. As an example: class SuperComplexAlgorithm { public: …
Markus Mayr
  • 4,038
  • 1
  • 20
  • 42
4
votes
2 answers

Boost threads - passing parameters by reference

My application has a section that resembles the following code void SomeClass::OtherMethod(std::vector& g) { g.pushback("Something"); } void SomeClass::SomeMethod() { std::vector v; boost::thread…
MistyD
  • 16,373
  • 40
  • 138
  • 240
4
votes
2 answers

remove_if with boost::bind is slow

I have a std::list of classes and want to remove entries that are marked for delete. I am using std::remove_if and erase. class MyClass { bool isDone(MyData& myData) { return myData.isDone(); } void…
Ant
  • 1,668
  • 2
  • 18
  • 35
4
votes
2 answers

Using boost::asio::io_service::post()

First i asked this Running a function on the main thread from a boost thread and passing parameters to that function so now i am trying this: The following is a console c++ project where i perfectly simulated my big…
Shereef Marzouk
  • 3,282
  • 7
  • 41
  • 64