Questions tagged [stdbind]

The C++11 function std::bind() fixes some or all arguments of a function object, returning another function object that takes fewer arguments.

std::bind performs Partial Function Application of arbitrary C++ function objects, fixing some or all arguments of a function object and returning another function object that takes fewer arguments.

The function is based on boost::bind() which originated in the library (see ) and an earlier version was included in as std::tr1::bind().

371 questions
2
votes
1 answer

Using std::bind to create a UnaryPredicate out of a BinaryPredicate to use in std::transform

I recently encountered this use of for_each: std::for_each(ts.begin(), ts.end(), [=](T& t){t *= f;}); Well, it works. For a container of Ts and a T f, this multiplies each value by f. However I dislike the use of the lambda here. It's short, but it…
stefan
  • 10,215
  • 4
  • 49
  • 90
2
votes
1 answer

Binding class member functions for boost::signals2

I have used std::bind to create a lambda involving a class member function but boost::signals2 won't accept it. I have a class Cut which I would like to inform when there is a new Event to look at by calling void Cut::newEvent(Event& e). I created a…
paco_uk
  • 445
  • 1
  • 5
  • 15
2
votes
0 answers

Launch a pthread with a lambda

For reasons outside of my control, I have to use pthreads with a decreased stack size. However, I do still have access to C++11, so I wanted to write something similar to std::async that would let me launch a pthread in detached state, and run any…
David Adrian
  • 1,079
  • 2
  • 9
  • 24
2
votes
1 answer

Mapping opaque arrays to function arguments using variadic templates and typelists

TLTR: I would like to map some arrays from a template container to the arguments of a function according to a specific order defined by indexes stored in a list of variadic templates (I can't think of a simpler way to define the problem). Arrays…
Thibaut
  • 2,400
  • 1
  • 16
  • 28
2
votes
2 answers

Strange template syntax in

I have been looking at the source code for std::function and std::bind in gcc-4.7.2, and came across some syntax used for member function pointers which I don't understand. What I don't understand is the specialisation of…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
2
votes
1 answer

std::function pointer to member function taking rvalue arguement MSVC2010 SP1

I would like to create a std::function bound to a member function taking a rvalue argument. Here is my attempt which does not compile ("xxfunction(154): error C2664: ... You cannot bind an lvalue to an rvalue reference" among others). class C …
odinthenerd
  • 5,422
  • 1
  • 32
  • 61
1
vote
1 answer

Why don't I need to std::move to a std::bind'ed function?

Let's say I have a function, taking an rvalue reference: void whatever (std::unique_ptr&&) { // Nothing! } ... and I bind its one parameter to a placeholder. auto f = std::bind(&whatever, _1); I tried the invocations like this, and the…
Andres Jaan Tack
  • 22,566
  • 11
  • 59
  • 78
1
vote
1 answer

How to generate a compile time initializer list of std::bind values?

I try to create an std::initializer_list of bind values, compile time using the following function. However, I can't get it correctly. template auto b(T t) -> auto { if constexpr (N == 0) { return…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
1
vote
1 answer

Using a vector of std::function to insert std::function

I would like to use polymorphism to have a vector of std::function that take in a base class as a parameter, and fill the vector with std::function with a similar signature that instead take in a derived class as a parameter. #include…
1
vote
2 answers

a question of std::bind expression evaluating

I read the item34: prefer lambdas to std::bind of "modern effective C++", it says Fixing the problem requires telling std::bind to defer evaluation of the expression until setAlarm is called, and the way to do that is to nest a second call to…
OverDrive
  • 27
  • 5
1
vote
2 answers

To transform std::bind to std::function?

See the code below queue > tasks; void add_job(function func, void* arg) { function f = bind(func, arg)(); tasks.push( f ); } func is the function I want to add to the tasks which has argument is…
Torch
  • 13
  • 4
1
vote
1 answer

How to get std::bind refer the explicit constructor defined in class while providing pointer to class member function as arguement?

I'm using std::bind in my code as shown below: std::bind(&Filter::odometryCallback, filter, std::placeholders::_1, odomTopicName, poseCallbackData, twistCallbackData); The Filter class has explicit constructors defined and hence…
1
vote
2 answers

C++ std::bind to std::function with multiple arguments

This question is going to be very much a duplicate, but I've read many of the examples on stack overflow and the common solution is not compiling for me, and I'm trying to figure out why. So I have a function I want to store in another class, the…
Natio2
  • 235
  • 1
  • 9
1
vote
0 answers

Compiler shows error, when i trying to binding handler with a socket (boost::asio)

When I trying to write this, like: this->_io_service.post( std::bind(this->_connection_handler, std::move(peer)) ); and compiler well generate lot of messages that i hard to understand. Error messages: n file included from…
Pipime
  • 11
  • 1
1
vote
0 answers

Argument siliently dropped by std::bind?

Below code confused me, I expected it can cause compiling error, but actually not. The stringmy string is silently dropped? As I understand TaskFunction expetec two arguments, but when I use std::bind there is one placeholder. Why didn't compiler…
bzhu
  • 908
  • 2
  • 9
  • 16