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

Storing boost::function objects in a container

I have a vector of KeyCallbacks: typedef boost::function KeyCallback which I use to store all listeners for when a keyboard button is pressed. I can add them and dispatch the events to all callbacks with for_each, but I do…
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
4
votes
2 answers

Boost bind and boost function, storing functions with arguments in a vector and then executing them

Sorry for the badly-worded title. I've been looking through the documentation, but I cannot find anything that might solve this problem I have. Basically I want to store several function1 , with arguments provided, in a vector, and…
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
3
votes
2 answers

Storing boost::bind functions in a std::map

I'm creating a bunch of functions which all effectively do the same thing: long Foo::check(long retValue, unsigned toCheck, const std::set& s) { auto it = s.find(toCheck); return (it == s.end()) ? -retValue : retValue; } where Foo…
Yuushi
  • 25,132
  • 7
  • 63
  • 81
3
votes
1 answer

llvm g++ and boost function

I'm trying to dertermine if the time overhead introduced by boost::function to evaluate mathematical functions is negligeable versus using function templates. The code for the benchmark I use is bellow. With traditionnal g++, overhead with…
user744629
  • 1,961
  • 1
  • 18
  • 27
3
votes
3 answers

how to combine 2 independent boost::bind() into one boost::function?

I have 2 functions f() and g(). I want to call them in order every time. Can I get a boost::function to do this? E.g. something like: boost::function functor = boost::bind( boost::bind(f), boost::bind(g) ); Extend this further, say it takes…
JQ.
  • 678
  • 7
  • 17
3
votes
2 answers

boost bind class function pointer

class Foo { double f1( int x, std::string s1 ); double f2( int x, SomeClass s2 ); } I want to be able to bind Foo.f1's s1 without an instance of foo to create in essense typedef double (Foo::* MyFooFunc)( int ) MyFooFunc func1 =…
Candy Chiu
  • 6,579
  • 9
  • 48
  • 69
3
votes
2 answers

Unresolved overloaded function type when using a template friend function

I have a problem where I'm trying to stuff a friend function of a class template into a boost::function: #include template struct Vec{ friend double dot(Vec, Vec){} }; template class Vec<2>; //Force multiple…
Gretchen
  • 2,274
  • 17
  • 16
3
votes
2 answers

Why can't I use a boost::function in an Objective-C++ block?

The following code throws an exception terminate called after throwing an instance of 'boost::exception_detail::clone_impl >' what(): call to empty boost::function at the…
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
3
votes
1 answer

Problem with boost::bind, boost::function and boost::factory

I'm trying without success to use a boost::bind with a boost::factory I have this class Zambas with 4 arguments (2 strings and 2 ints) and class Zambas { public: Zambas(const std::string&, const std::string&,int z1=0,int z2=0) { if…
Alexandre
  • 31
  • 2
3
votes
1 answer

C++ Boost function comparison

I have a class which contains boost::function as one of its arguments. I have to make this class equality comparable but the boost::function is not equality comparable. Is there a easy workaround for this problem? Thanks, Gokul.
Gokul
  • 893
  • 11
  • 27
3
votes
1 answer

How to parse a mathematical expression with boost::spirit and bind it to a function

I would like to define a function taking 2 arguments double func(double t, double x); where the actual implementation is read from an external text file. For example, specifying in the text file function = x*t; the function should…
srossi
  • 122
  • 1
  • 6
3
votes
1 answer

Boost.Lambda and Boost.Function don't play nicely with Boost.Array, why?

I'm running into extremely frustrating problems with Boost. When I try running something as simple as #include #include #include #include #include…
user541686
  • 205,094
  • 128
  • 528
  • 886
3
votes
1 answer

How to detect if a boost::function is pure virtual?

I've got a task pool using threads which is trying to call a boost::function that happens to be purely virtual, without an implementation. Is there anything like this? void doStuff(boost::function foo) { if (!foo.pure_virtual) …
bitcycle
  • 7,632
  • 16
  • 70
  • 121
3
votes
2 answers

How to clear boost function?

Having a non-empty boost::function, how to make it empty (so when you call .empty() on it you'll get true)?
DuckQueen
  • 772
  • 10
  • 62
  • 134
3
votes
2 answers

Parameter names in a std::function typedef

I know I can typedef a std::function like so: typedef std::function TextChangedHandler Is it permitted to specify parameter names in the typedef, in order to make it more self-documenting? For example: typedef…
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
1 2
3
10 11