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
3
votes
3 answers

bind two function objects

Building with clang++ -std=c++0x -stdlib=libc++ main.cpp #include #include using std::bind; using std::string; using std::function; class Service { public: void listen( const function< void ( const string&, const string&,…
Ben Crowhurst
  • 8,204
  • 6
  • 48
  • 78
3
votes
3 answers

C++ template function from callable class instance to std::function

I do need std::function for stateful operation. So I would like to make an instance of a class implementing operator() into std::function. I did test std::bind works, but can't wrap it up as a function. struct StatefulOperation { …
lighthouse
  • 413
  • 2
  • 10
3
votes
2 answers

Cannot get operator() pointer of std::bind() returned object

I need to extract the type of a function object parameter. Lambdas get translated into a closure object with the operator(). std::function has got the operator(), too. So, I can get a pointer to the operator() to pass to another function, in this…
Daniele Pallastrelli
  • 2,430
  • 1
  • 21
  • 37
3
votes
2 answers

How to store the returned callable from std::bind for a pointer to a member function?

I want to know how to declare an object of the return type of std::function when used with pointer to a member function: int main(){ void foo(std::string, int); string s = "hi"; auto fn = std::bind(foo, s, std::placeholders::_1); …
Itachi Uchiwa
  • 3,044
  • 12
  • 26
3
votes
1 answer

What exactly std::function() does when stored in a container?

What exactly std::function constructor does when stored in a container ? In this test codes: struct A { int sn; A() = delete; A(int v) : sn(v) { cout << "A::init(" << sn << ')' << endl; } A(const A& a) : sn(a.sn+1) { cout <<…
RichardLiu
  • 1,902
  • 1
  • 19
  • 18
3
votes
2 answers

Should we check a function not empty before applied with std::bind?

std::function f; std::function binded_f = std::bind(f, true); std::cout << (f != nullptr) << " " << (binded_f != nullptr) << "\n"; f(true); binded_f(); Above code gave output 0 1, and binded_f() crash with Unhandled exception at…
heLomaN
  • 1,634
  • 2
  • 22
  • 33
3
votes
4 answers

std::function works beautifully with std::bind - but why?

I was using a std::uniform_int_distribution to generate primes (p). I put the distribution object in an anonymous namespace - which seems like C++ 'static linkage' for grown-ups... namespace { // a more pedantic range: [2, 18446744073709551557] …
Brett Hale
  • 21,653
  • 2
  • 61
  • 90
3
votes
1 answer

std::function and std::bind return value

I'm trying to understand how std::bind and std::function work. I cannot get the following code to compile: #include #include #include void function(int a, float b, std::string const &s) { std::cout << "printing…
Luca
  • 1,658
  • 4
  • 20
  • 41
3
votes
2 answers

no type named 'type' in class std::result_of

The following code just wouldn't compile: template< typename Fn > bool templateFunctionOne( Fn&& fn ) { int v = 5; return fn( v ); } template < typename Fn > bool templateFunctionTwo( Fn&& fn ) { std::future< bool > tk( std::async(…
mark
  • 89
  • 1
  • 6
3
votes
1 answer

std::bind to void* to std::function

I'm trying to make an event system The user of this system have to execute this to add an event for input for e.g: addEventHandler(Event::KEYBOARD_INPUT, reinterpret_cast(&std::bind(&Game::On_Input, this))); the function passed gonna be…
Omarito
  • 577
  • 6
  • 22
3
votes
1 answer

How to store std::bind result to std::function

I want to store a callback to a std::function> object. When I use lambda, it works fine. But when I use std::bind to a member function, it compiled error. There is the sample error code. #include #include using…
Alexander Chen
  • 417
  • 3
  • 17
3
votes
1 answer

std::binding to a lambda: compilation error

I ran into an error trying to std::bind to a lambda. The following code sample compiles fine: #include #include int main() { const auto lambda1 = [](int a, int b){ return a + b; }; std::cout << (std::bind( lambda1,…
BobMorane
  • 3,870
  • 3
  • 20
  • 42
3
votes
1 answer

C++ std::function bind from derived class

If I had a base class MessageWrapper, with a child class SetConfigurationData, why does binding with a child class parameter not work? Shouldn't it work polymorphically? Class MessageHandler { public: void…
user2654735
  • 323
  • 5
  • 19
3
votes
1 answer

can't assign std::bind return value to std::function

I have been trying to write a very simple piece of code but it doesn't seems to work and I am unable to make any sense out of the compiler error. code: #include #include #include class c { public: void…
helix
  • 1,017
  • 3
  • 12
  • 30
3
votes
1 answer

false-positive error using std::functional in vs2015

I have implemented some test functionals yesterday and everything compiled and worked fine without errors. Today i came back to my PC and my std::bind's are underlined red but compile without error. Seems like Intellisense and the compiler do not…
coJetty
  • 47
  • 3