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

How to use std::for_each on a range of boost::function objects?

class User { public: User(){} virtual ~User(){} void Test( int in ) { } } User user; vector< boost::function< void() > > functions; functions.push_back( boost::bind( &User::Test, &user, 2 )…
metdoloca
  • 21
  • 2
2
votes
1 answer

Template overloading (diff. number of arguments)

I wanted to create these function templates you see below. Their purpose is to compare functors, but I needed to cover a special case for the boost.bind type of functors. template void…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
2
votes
3 answers

Determine object and method in a functor using boost::function and boost::bind

I'd like to obtain the pointer to the object and an indication of which method the functor will call from a functor constructed using boost::function and boost::bind. This will allow me to automatically determine the order in a which bunch of…
lasser
2
votes
1 answer

Problem replacing boost::bind with std::tr1::bind

I have the following code which compiles and runs fine under Visual Studio 2008 SP1. #include #include #include #include #include #include…
PeteUK
  • 1,062
  • 12
  • 26
2
votes
2 answers

Identify objects in boost::shared_ptr

I am building an application based on an example on the boost website. These are the relevant definitions to know of: typedef boost::shared_ptr< connection > connection_ptr; std::set< connection_ptr> connections_; std::vector<…
Thomas Johansson
  • 583
  • 2
  • 6
  • 15
2
votes
1 answer

invalid use of non-static member function when using boost bind - c++

I'm trying to generate a periodic timer class using the boost.asio library. However, I get "invalid use of non-static member function" errors. The cpp file is as the following: #include "TimerBoost.h" #include #include…
2
votes
2 answers

Can I store bound functions in a container?

Consider the following code: void func_0() { std::cout << "Zero parameter function" << std::endl; } void func_1(int i) { std::cout << "One parameter function [" << i << "]" << std::endl; } void func_2(int i, std::string s) { std::cout…
Sharath
  • 1,627
  • 2
  • 18
  • 34
2
votes
2 answers

boost::bind and reference to temp variable

Suppose I have method: void foo(const std::string& s); Can I create boost::function: boost::function f = boost::bind(foo, temp); where temp is char* that is deleted before f is called.
dimba
  • 26,717
  • 34
  • 141
  • 196
2
votes
2 answers

When does boost::bind cast arguments to the required type?

When I use boost::bind to bind parameters to a function - when are they casted to the type required by the function (if an implicit cast is possible)? How are they stored in the bind_t object? As the type originally passed to bind or as the type…
Hannah S.
  • 3,081
  • 3
  • 20
  • 27
2
votes
2 answers

"Interface" like semantics with boost::bind

I wanted to be able to have something like Java's interface semantics with C++. At first, I had used boost::signal to callback explicitly registered member functions for a given event. This worked really well. But then I decided that some pools…
Brian Cain
  • 23
  • 4
2
votes
2 answers

boost::function deallocation segmentation fault in thread pool

I'm trying to make a thread pool that blocks the main thread until all it's children have completed. The real-world use-case for this is a "Controller" process that spawns independent processes for the user to interact with. Unfortunately, when the…
Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
2
votes
1 answer

Compile error on boost::bind ( member function) in spirit parser action on context argument

I use vc14 and boost version is 1.60. #include #include #include #include #include #include…
2
votes
4 answers

How to call a member function on a parameter with std::for_each and boost::bind?

I want to add a series of strings to a combo box using std::for_each. The objects are of type Category and I need to call GetName on them. How can I achieve this with boost::bind? const std::vector &categories =…
Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
2
votes
3 answers

Pointers to functions

I have to pass function into pointer. For this purposes I'm using boost::function. The function which catches the pointer is overloaded for different signatures. For example: void Foo(boost::function) { ... } void Foo(boost::function
Max Frai
  • 61,946
  • 78
  • 197
  • 306
2
votes
1 answer

Why boost::bind incompatible with forward declaration?

boost::bind is unable to bind parameters declared via a forward declaration. Can anyone explain why? Is this a boost bug? Sample code: #include "boost/function.hpp" #include "boost/bind.hpp" #include #include class B; class…
jpo38
  • 20,821
  • 10
  • 70
  • 151