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

Delete raw pointer argument to boost::bind

Lets say I have heap allocated A*, which I want to pass as argument to boost::bind. boost::bind is saved for later processing in some STL like container of boost::functions's. I want to ensure A* will be destroyed at destruction of the STL…
dimba
  • 26,717
  • 34
  • 141
  • 196
6
votes
2 answers

Pass and call a member function (boost::bind / boost::function?)

I have a probably embarassingly simple problem: pass and call a member function in a class. I know I want to use BOOST bind (and or function), but I haven't really grasped the concept to it yet. The following code compiles and executes with problem.…
BaCh
  • 625
  • 2
  • 5
  • 17
6
votes
2 answers

How can I use boost::bind to bind a class member function?

#include #include #include class button { public: boost::function onClick; boost::function onClick2; }; class player { public: void play(int…
codebeing
  • 127
  • 2
  • 11
5
votes
2 answers

Does copying a boost::function also copy the closure?

Say I have a function like this: void someFunction(const ExpensiveObjectToCopy&); If I make a boost::function out if it, that function will store its own cloned copy of the object in its closure: boost::function f =…
Chris
  • 6,642
  • 7
  • 42
  • 55
5
votes
2 answers

How serialize a boost::function to send it in a message_queue

I am actually trying to serialize a boost::function using boost::serialize because I want to share it in a boost::interprocess::message_queue. I only see one way to do that, it is to use the non-intrusive version of boost::serialize. namespace boost…
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

C++ virtual function call versus boost::function call speedwise

I wanted to know how fast is a single-inheritance virtual function call when compared to one same boost::function call. Are they almost the same in performance or is boost::function slower? I'm aware that performance may vary from case to case, but,…
Gui Prá
  • 5,559
  • 4
  • 34
  • 59
5
votes
1 answer

Has boost::function's default constructor the no-throw guarantee?

The question is in the title. I cannot find the information in the reference documentation. I do not see why the default constructor would throw, but I need to be sure it is no-throw to correctly document my exception guarantees.
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
4
votes
1 answer

How does boost::function support template class with different length template parameters

I want to use boost preprocessor to declare template classes with different template variable length, basically like what boost::function does. #if !BOOST_PP_IS_ITERATING #ifndef D_EXAMPLE_H #define D_EXAMPLE_H #include #include…
Jason
  • 259
  • 1
  • 3
  • 12
4
votes
4 answers

How can I make boost::function not be so lenient?

typedef boost::function MyCallback; void RegisterCallback(MyCallback callback); class A { public: void GoodCallback(int intArg,bool boolArg) { printf("calling GoodCallback (%d,%s)\n",intArg,boolArg?"true":"false"); …
IronMensan
  • 6,761
  • 1
  • 26
  • 35
4
votes
2 answers

Applying C++11 move semantics to bound functions

I have some existing C++98 code that makes use of boost::function and boost:bind for asynchronous callbacks. Some relevant simplified fragments of the code include: typedef boost::function
Miral
  • 12,637
  • 4
  • 53
  • 93
4
votes
1 answer

std::tr1::function::target and co-/contravariance

Since I love progamming in both C# and C++, I'm about to implementing a C#-like event system as a solid base for my planned C++ SFML-GUI. This is only an excerpt of my code and I hope this clarifies my concept: // Event.h // STL headers: #include…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
4
votes
1 answer

boost::function vs function pointers

I'm implementing a generic setting reader. The idea is that I have an application which settings can be boolean, integers and strings. Then I have a Config class where the getters for such settings are implemented, the config class takes a customer…
codeJack
  • 2,423
  • 5
  • 24
  • 31
4
votes
2 answers

Post callbacks to a task queue using boost::bind

Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2(). Everything is the same except that, when triggered, it needs to post it…
1
2
3
10 11