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

How can I store a boost::bind object as a class member?

I'm writing an application that uses boost::asio. Asio's async_receive (or async_read) is invariably shown using a boost::bind object given for callback: boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(), …
Gabriel
  • 2,841
  • 4
  • 33
  • 43
5
votes
1 answer

"no match for call" error using boost::bind

I'm still new to boost::bind, and now porting a program that was written 2 yrs ago in 2009, seeing the compile error below. Any idea to workaround would be appreciated. Extracted cpp file: class ClassA { private: cNamespace::Bounds…
IsaacS
  • 3,551
  • 6
  • 39
  • 61
5
votes
2 answers

How to create a function with argument that would be result of boost::bind?

So I want to create a function like: void proxy_do_stuff(boost::bind return_here) { return_here(); // call stuff pased into boost::bind } And I could call it like : proxy_do_stuff(boost::bind(&myclass::myfunction, this,…
Rella
  • 65,003
  • 109
  • 363
  • 636
5
votes
2 answers

Is it possible to create a function pointer to the a function's `new` operator/constructor?

If I were to wanted to parameterize creating an object, I could of course make a function which called new on a particular class and passed out a pointer. I am wondering if it's possible to skip that step and pass a function pointer to the new…
Catskul
  • 17,916
  • 15
  • 84
  • 113
5
votes
1 answer

Boost bind and 'result_type': is not a member, c++03-friendly

The latest 16.6 update to Visual Studio 2019 removed std::plus::result_type, std::minus::result_type, and related typedefs. (They're deprecated in C++17 and removed in C++20.) A greatly simplified version of the code looks like this: template…
MaddHatter
  • 63
  • 1
  • 3
5
votes
2 answers

no. of arguments in boost::bind

How many maximum arguments can we pass to boost::bind()
Shweta
  • 5,198
  • 11
  • 44
  • 58
5
votes
2 answers

How to force template function overload for boost::bind?

I'm trying to create predicate for std::find_if by using boost::bind together with boost::contains (from boost/algoritm/string library). Following snippet shows two ways how I'm trying to accomplish this. #include…
lollinus
  • 434
  • 4
  • 11
5
votes
1 answer

Distinguish between const and non-const method with same name in boost::bind

When I use boost::bind with a method name which is declared both const and non-const I am getting in ambiguous error, for example boost::bind( &boost::optional::get, _1 ) How can I solve this problem?
Mathias Soeken
  • 1,293
  • 2
  • 8
  • 22
5
votes
1 answer

passing a boost::function to a template; what class is boost::function

I need to pass a distance-function to a template. Therefore I use boost::function and boost::bind. But I do not understand what I have to pass for class Distance: template class CoverTree { Distance…
user__42
  • 543
  • 4
  • 13
5
votes
1 answer

Chained invocation of C++11 std::bind doesn't work

I have a problem when invoking nested std::bind expressions. The following code demonstrates the problem. It fails to compile with libc++, but works with boost: #define BOOST 0 #if BOOST #include #include…
marton78
  • 3,899
  • 2
  • 27
  • 38
5
votes
2 answers

Am I reinventing the wheel with this trivial method call forwarding class?

I just found myself creating a class template struct invoker { void operator()(T& it) const {it();} }; so I could pass an invoker to something (which isn't under my control) which wants to call invoker::operator()(foo&) on…
timday
  • 24,582
  • 12
  • 83
  • 135
4
votes
3 answers

Passing values to atexit

I want to push a series of clean up functions as they are needed. I was using atexit to do this for one cleanup function without any parameters, but I am not sure how to expand this approach to more then one clean up function. I am not very familiar…
Mikhail
  • 7,749
  • 11
  • 62
  • 136
4
votes
2 answers

boost::bind doesn't work with boost::tuple::get()

I am trying to use boost::bind and STL with boost::tuple, but each time I try to compile I get the following error. error: call of overloaded ‘bind(, boost::arg<1>&)’ is ambiguous Do you know what I…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
4
votes
2 answers

Why might std::bind1st be considered "almost unusable"?

During a conversation on boost::bind, it was noted that std::bind1st exists in C++03, but that it is "almost unusable". I can't find anything solid to back this up. The boost::bind documentation says: boost::bind is a generalization of the …
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
4
votes
1 answer

How to define and use boost::function with "optional arguments"?

I am using a class that needs some kind of callback method, so i'm using boost::function to store the function pointers. i need the callback to have one optional argument, but i found out that boost::function won't let me define optional arguments…