The boost-function tag has no wiki summary.
21
votes
2answers
18k views
How to use boost bind with a member function
The following code causes cl.exe to crash (MS VS2005).
I am trying to use boost bind to create a function to a calls a method of myclass:
#include "stdafx.h"
#include <boost/function.hpp>
...
12
votes
1answer
619 views
Is using boost::bind to pass more arguments than expected safe?
Using boost-bind, the resulting boost-function may receive more arguments than the bound object expects. Conceptually:
int func() { return 42; }
boost::function<int (int,int,int)> boundFunc = ...
9
votes
1answer
193 views
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&)
{
...
7
votes
3answers
3k views
boost::function run-time performance
I'm in the process of implementing a platform independent wrapper for dynamically loaded libraries. Of course when I load functions from the libraries I need to store them as pointers for future use. ...
7
votes
1answer
404 views
Can tr1::function swallow return values?
The boost::function FAQ item 3 specifically addresses the scenario I am interested in:
Why are there workarounds for void
returns? C++ allows them! Void returns
are permitted by the C++ ...
7
votes
1answer
518 views
C++ weird syntax spotted in Boost template parameters
I was having a look at the "Function" class documentation in Boost, and stumbled across this:
boost::function<float (int x, int y)> f;
I must admit this syntax is highly confusing for me. ...
7
votes
2answers
1k views
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 <boost/thread.hpp>
void ...
6
votes
2answers
3k views
Default value for boost::function argument?
I've got a function that I want to take an optional boost::function argument as a callback for reporting an error condition. Is there some special value I can use a the default value to make it ...
5
votes
4answers
645 views
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* ...
5
votes
1answer
264 views
When to use std::function instead of inheritance?
In some cases std::function can replace inheritance. The following two code snippets are very similar (about the same costs when calling the function, almost the same usage in signatures and in most ...
5
votes
1answer
1k views
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 ...
5
votes
3answers
8k views
Class member function as callback using boost::bind and boost::function
I'm working through setting up a member function as a callback for a C-library that I'm using. The C-library sets up callbacks like this:
typedef int (*functionPointer_t)(myType1_t*, myType2_t*, ...
5
votes
1answer
78 views
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 DataType, class ...
4
votes
2answers
1k views
How can I use boost::bind to bind a class member function?
#include <QtCore/QCoreApplication>
#include <boost/bind.hpp>
#include <boost/function.hpp>
class button
{
public:
boost::function<void()> onClick;
...
4
votes
2answers
3k views
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 ...