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

how boost::function and boost::bind work

I dislike having magic boxes scattered all over my code...how exactly do these two classes work to allow basically any function to be mapped to a function object even if the function<> has a completely different parameter set to the one im passing…
Fire Lancer
  • 29,364
  • 31
  • 116
  • 182
81
votes
3 answers

How to use boost bind with a member function

The following code causes cl.exe to crash (MS VS2005). I am trying to use boost bind to create a function to a calls a method of myclass: #include "stdafx.h" #include #include #include class…
hamishmcn
  • 7,843
  • 10
  • 41
  • 46
73
votes
4 answers

Difference between C++11 std::bind and boost::bind

Is there any difference between the two? Or am I safe to replace every occurrence of boost::bind by std::bind in my code and thereby remove the dependence on Boost?
Haatschii
  • 9,021
  • 10
  • 58
  • 95
33
votes
3 answers

How does boost bind work behind the scenes in general?

Without spending a long time reviewing the boost source code, could someone give me a quick rundown of how boost bind is implemented?
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
31
votes
2 answers

boost::bind with functions that have parameters that are references

I noticed that when passing reference parameters to boost bind, those parameters won't act like references. Instead boost creates another copy of the member and the original passed in variable remains unchanged. When I change the references to…
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
26
votes
1 answer

What is the return type of boost::bind?

I want to save the "binder" of a function to a variable, to use it repetitively in the following code by exploiting its operator overloading facilities. Here is the code that actually does what I want: #include #include…
Kostya
  • 1,072
  • 11
  • 24
25
votes
1 answer

Is using boost::bind to pass more arguments than expected safe?

Using boost-bind, the resulting boost-function may receive more arguments than the bound object expects. Conceptually: int func() { return 42; } boost::function boundFunc = boost::bind(&func); int answer = boundFunc(1,2,3); In…
Jeff Benshetler
  • 640
  • 6
  • 13
22
votes
6 answers

Calling base class definition of virtual member function with function pointer

I want to call the base class implementation of a virtual function using a member function pointer. class Base { public: virtual void func() { cout << "base" << endl; } }; class Derived: public Base { public: void func() { cout << "derived"…
Eddie
21
votes
3 answers

How to implement generic callbacks in C++

Forgive my ignorance in asking this basic question but I've become so used to using Python where this sort of thing is trivial that I've completely forgotten how I would attempt this in C++. I want to be able to pass a callback to a function that…
Kylotan
  • 18,290
  • 7
  • 46
  • 74
18
votes
4 answers

Why can't std::bind and boost::bind be used interchangeably in this Boost.Asio tutorials

I was trying the differents tutorials in Boost.Asio documentation and tried to replace boost components with C++11 ones. However, I got an error using std::bind in Timer.5 - Synchronising handlers in multithreaded programs. Here is the code…
authchir
  • 1,605
  • 14
  • 26
16
votes
5 answers

boost shared_from_this<>()

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…
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
15
votes
2 answers

boost::bind and class member function

Consider following example. #include #include #include #include void func(int e, int x) { std::cerr << "x is " << x << std::endl; std::cerr << "e is " << e << std::endl; } struct foo { …
Konstantin
  • 6,061
  • 8
  • 40
  • 48
15
votes
2 answers

Help me understand this usage of boost::bind

Please have a look at this example posted by Johannes Schaub to sort a vector of pairs: How do I sort a vector of pairs based on the second element of the pair? std::sort(a.begin(), a.end(), boost::bind(&std::pair::second, _1)…
nabulke
  • 11,025
  • 13
  • 65
  • 114
13
votes
3 answers

Partial Binding of Function Arguments

Is there a way to partially bind the first/last n arguments of a callable object (e.g. function) without explicitly specifying the rest of the arguments? std::bind() seems to require that all the arguments are be bound, those that are to be left…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
13
votes
1 answer

If ampersands aren't needed for function pointers, why does boost::bind require one?

I've always believed that function pointers don't require an ampersand: Do function pointers need an ampersand Yet, every example I've seen of using boost::bind shows one, and my compiler - in most situations - gives a typically inscrutable error…
Roddy
  • 66,617
  • 42
  • 165
  • 277
1
2 3
23 24