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

How do you declare an extern "C" function pointer

So I have this code: #include "boost_bind.h" #include #include #include double foo(double num, double (*func)(double)) { return 65.4; } int main(int argc, char** argv) { std::vector vec; …
Salgar
  • 7,687
  • 1
  • 25
  • 39
12
votes
2 answers

Difference between boost::bind, boost::lambda::bind and boost::phoenix::bind

I am trying to understand the difference between these different bind approaches. There is a similar question at boost::bind and boost::phoenix::bind But, if anyone can explain this with examples it would be great. Also is it true that…
polapts
  • 5,493
  • 10
  • 37
  • 49
12
votes
2 answers

Can I use (boost) bind with a function template?

Is it possible to bind arguments to a function template with (boost) bind? // Define a template function (just a silly example) template ARG1 FCall2Templ(ARG1 arg1, ARG2 arg2) { return arg1 + arg2; } // try to bind…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
12
votes
1 answer

Why is "boost::function = boost::bind(...)" creating 13 temporaries?

I have some pretty basic test code. I have a class that just logs all operations on it. I bound it to a boost::function object like this: void Function(const Foo&) { printf("Function invoked\n"); } // ... …
David Schwartz
  • 179,497
  • 17
  • 214
  • 278
11
votes
2 answers

How to use boost::bind with non-copyable params, for example boost::promise?

Some C++ objects have no copy constructor, but have move constructor. For example, boost::promise. How can I bind those objects using their move constructors ? #include void fullfil_1(boost::promise& prom, int x) { …
user222202
  • 523
  • 4
  • 14
11
votes
3 answers

About shared_ptr and pointer to member operator `->*` and `std::bind`

Recently I discovered that shared_ptr does not have pointer to member operator ->*. I created simple example: template auto invoke1(Pointer p, Function f, Args... args) ->…
PiotrNycz
  • 23,099
  • 7
  • 66
  • 112
11
votes
2 answers

How to use boost::bind in C++/CLI to bind a member of a managed class

I am using boost::signal in a native C++ class, and I now I am writing a .NET wrapper in C++/CLI, so that I can expose the native C++ callbacks as .NET events. When I try to use boost::bind to take the address of a member function of my managed…
Brian Stewart
  • 9,157
  • 11
  • 54
  • 66
11
votes
2 answers

Boost::Bind and virtual function overloads: why do they work?

I wrote some code and got scared that it will not work - so I wrote a prototype: #include #include #include class base { private: boost::function action; protected: virtual void…
DuckQueen
  • 772
  • 10
  • 62
  • 134
11
votes
4 answers

How do you pass boost::bind objects to a function?

I have a one-dimensional function minimizer. Right now I'm passing it function pointers. However many functions have multiple parameters, some of which are held fixed. I have implemented this using functors like so template minimize(T…
Tristan
  • 6,776
  • 5
  • 40
  • 63
10
votes
1 answer

What's the use of asio::placeholder::error

The asio library passes an error parameter in a lot of its examples, ie; http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp What's the point of this parameter? Does asio actually populate this parameter with…
kvanbere
  • 3,289
  • 3
  • 27
  • 52
10
votes
1 answer

Can I boost::bind() to an Objective C function?

I have no idea if this is possible, but if it is, what would the syntax look like? If not possible, why not?
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
9
votes
2 answers

Using for_each and boost::bind with a vector of pointers

I have a vector of pointers. I would like to call a function for every element, but that function takes a reference. Is there a simple way to dereference the elements? Example: MyClass::ReferenceFn( Element & e ) { ... } MyClass::PointerFn(…
Alex Deem
  • 4,717
  • 1
  • 21
  • 24
9
votes
1 answer

How to cast to it boost::bind(&myClass::fun, this, _1, _2, _3) to typedef void (*fun)(arg1, arg2, arg3)?

In lib Bullet there is defined a type: typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo); in there docs there is presented a sample of usage (page 23): void…
DuckQueen
  • 772
  • 10
  • 62
  • 134
8
votes
3 answers

How can I use Boost.Bind on compound types?

I have std::map >, and I need to find the minimal short in this map. How can I use boost::bind with std::min_element() for this? boost::lambda?
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
8
votes
5 answers

Getting return value from a boost::threaded member function?

I have a worker class like the one below: class Worker{ public: int Do(){ int ret = 100; // do stuff return ret; } } It's intended to be executed with boost::thread and boost::bind, like: Worker worker; boost::function
He Shiming
  • 5,710
  • 5
  • 38
  • 68
1
2
3
23 24