Questions tagged [boost-function]

A Boost C++ library that provide a family of class templates that are function object wrappers, similar to generalized callbacks.

The Boost.Function library defines boost::function, a class template that is callable like a function, and wraps another callable type and forwards calls to it.

Boost.Function was proposed for standardisation and was included in the Technical Report on C++ Library Extensions () as std::tr1::function and included in the C++ 2011 standard as std::function ().

162 questions
1
vote
2 answers

boost::function and plain function pointers: ambigous overload

Given the following member function overload to take various functors class Foo { public: void bar(boost::function func); void bar(boost::function func); void bar(boost::function
Phil
  • 11
  • 2
1
vote
2 answers

Shortening boost::function

When passing a boost::function as a parameter to another function (callback), this function's signature can become quite long. Example: Consider this boost::function: boost::function
gpalex
  • 826
  • 1
  • 11
  • 27
1
vote
0 answers

Assigning a function to a boost::function member variable where it is defined requires constructor?

I am trying to assign a function to a boost::function in a class member variable definition: #include #include double Function0() { std::cout << "Function0()" << std::endl; return 2.2; } template
David Doria
  • 9,873
  • 17
  • 85
  • 147
1
vote
1 answer

How can I use a boost function to transform the parameter types?

I want to create a boost function object of the following signature: void (int, boost::uuid); However, I would like to bind it to a function of the following form: void (SomeType, boost::uuid) Where the SomeType argument comes from another…
stix
  • 1,140
  • 13
  • 36
1
vote
1 answer

C++: How do I pass a pointer to a member function of another class?

How would the signature for function Foo() fo class classA have to look when I want to pass a pointer to a function that is a member of classB? Function update() is called on an isntance of classB and gets passed an object of classA. Inside update()…
tzippy
  • 6,458
  • 30
  • 82
  • 151
1
vote
1 answer

boost::bind() binds extra arguments?

Does boost::bind() bind binds extra arguments as it seems passing a bind function with no arguments into one expecting an argument double works fine? If I were to write out the bind function explicitly, what should that be? struct MyClass { …
surfcode
  • 445
  • 1
  • 5
  • 20
1
vote
1 answer

Populating the std::map of boost::function with boost::assign::map_list_of

I would like to create a key-value data structure that would be useful for responding to the events of string matching to regex patterns. So I am trying to work it out with a Boost library: #include #include…
Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
1
vote
1 answer

Getting object that contains the member function from boost function created with bind

void someFunction(boost::function func) { ... //Get myObj } MyClass *myObj = ...; someFunction(boost::bind(&MyClass::memberFunction, myObj)); How can I get pointer or reference to myObj from inside the function void someFunction
Saif Ur Rehman
  • 338
  • 3
  • 14
1
vote
1 answer

What is wrong with this boost::lambda use?

Why is this boost::lambda expression not working? boost::function myFunct = boost::lambda::_3 < 1; I get theses compilation errors, that won't probably help, because they are really…
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
1
vote
2 answers

Delegating to boost::function with arbitrary signature

I'm trying to create something like a boost::function, but with an extra 'smart handle' tucked inside, which controls the lifetime of a resource the functions needs to execute correctly. If I didn't need the function signature to be completely…
thehouse
  • 7,957
  • 7
  • 33
  • 32
1
vote
2 answers

STL algorithms on containers of boost::function objects

I have the following code that uses a for loop and I would like to use transform, or at least for_each instead, but I can't see how. typedef std::list CallbackList; CallbackList…
Dan Hook
  • 6,769
  • 7
  • 35
  • 52
1
vote
0 answers

How to get function pointer from boost::function object

There are other solutions on StackOverflow like this which suggest same way of converting boost::function into function pointer. But the same code generates error for me. Do I need to introduce reinterpret_cast or there is a cleaner why of doing…
Vishnu Kanwar
  • 761
  • 5
  • 22
1
vote
1 answer

Boost::function bound member function becomes invalid

I have a simple thread pool implementation using boost::function, and boost::bind to reduce the member function signature to void func(void). This then uses a queue of boost::function and int pairs, pops the top of the queue, and executes the…
Oxonium
  • 11
  • 3
1
vote
1 answer

boost::function with function templates

#include #include #include "boost/function.hpp" template static void FOREACH (T1 cont, boost::function callback) { typename T1::iterator it = cont. begin (); for ( ; it != cont.…
1
vote
2 answers

Comparing function pointers stored as boost::function

I have a list of boost::function objects and am trying to find a specific one so I can remove it from the list. Effectively a function is registered (pushed onto a vector) and I wish to be able to unregister it (search the vector and remove the…
pugdogfan
  • 311
  • 3
  • 10