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

Getting function object for overload set

This code doesn't work, because &f creates a function pointer to only one of the the two f() functions, so the compiler doesn't know which one: #include #include void f(int i) { std::cout << "f(int)" << std::endl; } void…
tmlen
  • 8,533
  • 5
  • 31
  • 84
2
votes
1 answer

Is there a way to create a hash of a function wrapped by `std::function<>`?

I have a C++ function that takes a std::function as an input argument. Specifically, a std::function. In my use-case, the caller may bind the std::function to either a free function or a member function. (I'm not…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
2
votes
1 answer

Compilation Error due to Boost::Asio::Spawn function

RE: https://www.boost.org/doc/libs/1_80_0/libs/beast/example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp I tried following the above example and ran into a compilation error; namely, code C2039: 'type': is not a member of…
2
votes
1 answer

std::bind and std::function term does not evalue as taking 0 arguments?

I'm working on generic class that will be used to run functions of different prototype for performance testing of algorithms. I stuck because std::function can't execute what it was bound with, here is sample code, with comment where the error…
metablaster
  • 1,958
  • 12
  • 26
2
votes
2 answers

How to bind 'this' using templates instead of macros?

I am trying to replace all macros in my code with templates. I have a macro that binds this as the first argument to a function so that a member function can be used in a static context. How can I achieve that with templates? I would like this…
Rudolf Lovrenčić
  • 147
  • 1
  • 2
  • 9
2
votes
1 answer

unable to convert return value of std::bind to void function pointer

I am new to functional library. I want to bind a static class method with the object of the class and return a void pointer to the function. I tried using std::bind but it cannot convert a class member function to free floating pointer to the…
sam91
  • 77
  • 7
2
votes
1 answer

Modifying an inherited member variable does not affect base class

I have the following two classes: class A { public: A() : value(false) {} bool get() const { return value; } protected: bool value; }; class B : public A { public: void set() { value = true; …
2
votes
1 answer

Why can I store a callable target in a std::function which dosen't match the type

I have tried the following: typedef std::function callback; struct testclass { void testfunc() { printf("test\n"); } }; int main() { testclass test; callback c = std::bind(&testclass::testfunc, &test); …
M.Duo
  • 23
  • 3
2
votes
2 answers

C++ binding overloaded member function and passing as parameter

I have a class with two functions which start and stop a collection of things. As the two functions are identical except that they ultimately call a start or stop function on each thing respectively, I would like to refactor the code so that I move…
Component 10
  • 10,247
  • 7
  • 47
  • 64
2
votes
2 answers

Try to create C# style event access modifier in C++ using std::functional and std::bind

I'm trying to create C# style event handling, i.e expose += operator for everybody and expose Invoke method only for the containing class. I'm using std::functional and std::bind as explained here to create callback mechanism: C++ callback using…
OdedR
  • 133
  • 7
2
votes
1 answer

Passing const class object to std::function and std::bind lead compilation error

When const Serviceclass used in std::function leads to compilation error. If remove const the complication is successful. Code Flow : Client::GetValue() is called which calls on Server::datalist() QUESTION : Why can't i use const on Serviceclass…
josp
  • 97
  • 5
2
votes
2 answers

Why does std::bind statically type check arguments passed to the function?

Not exactly a question but more of a musing... I wrote a program to test how 'std::bind' passes arguments to the function being binded. It seems like in this instance the C++ compiler performs static type checking: #include #include…
laker93
  • 498
  • 4
  • 9
2
votes
0 answers

Multiple Callback registration causes Segmentation Fault in c++,

I am trying to register the Multiple Functions for callback using std::function and trying them to get called back whenever some event occurs. class DemoClass { public: DemoClass(); void Callback1(int x); void…
spt025
  • 2,134
  • 2
  • 20
  • 26
2
votes
2 answers

How std::bind(&T::memberFunc, this) can always bind to std::function regardless of what T is?

As far as I know, the member function pointer only can be assigned to the pointer to member function type, and converted to any other except this will violate the standard, right? And when calling std::bind(&T::memberFunc, this), it should return a…
Francis
  • 737
  • 1
  • 7
  • 21
2
votes
1 answer

Efficiency of std::bind vs lambda

I have searched around a bit and found many examples and discussions of cases where you would use std::bind instead of a lambda, but the burning question I have is whether or not there is any performance benefit to one over the other. I will…
tbotz
  • 167
  • 2
  • 7