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
1
vote
1 answer

std::function accepting different function signatures in c++

I'm trying to create a c++ event system similar to c# system. I need to be able to store any kind of functions and call them with the right parameters at the appropriate time. The closest I can get is with std::function, bind and placeholders but…
Manspider
  • 353
  • 3
  • 17
1
vote
0 answers

Custom allocator for std::bind

Perhaps the topic of std::bind and std::function is not clear enough to me - then, please, clarify. I'm trying to implement a thread pool (like this), but to avoid std::function and std::bind performance penalty due to heap allocations for the…
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
1
vote
2 answers

ability to run a packaged task with std::bind function parameters in a seperate thread via template function

The question i have is the line where i indicate ERROR below gives error as std::thread constructor works out the function to be invoked and requires the parameter as needed by the function signature. Is there any way to solve this ? if i attempt…
Anand Kulkarni
  • 395
  • 1
  • 2
  • 10
1
vote
1 answer

const pointer as std::bind parameter

The following code #include #include using namespace std; struct TestStruct { int c; }; int f(int a, int b, const TestStruct **t) { return a + b + (*t)->c; } void main() { TestStruct *t; bind(&f, 1, 2,…
perencia
  • 1,498
  • 3
  • 11
  • 19
1
vote
2 answers

std::bind fails to compile with std::atomic_bool& on MSVC

I'm using VC++ to compile my program (using Visual Studio 2015, update 3) and some snippet fails to compile. basically, I want to bind a function which gets a reference to atomic boolean with atomic boolean. self containing code: void…
David Haim
  • 25,446
  • 3
  • 44
  • 78
1
vote
1 answer

Cast std::bind function pointer to void* and back

Let's say I want to bind a function and then pass it to another function as a void *, and cast it back. I have a global function in which I try to cast the function: void function_wrapper(void * func){ std::function&,…
user650261
  • 2,115
  • 5
  • 24
  • 47
1
vote
1 answer

Rebinding a function pointer in copy constructor

I have a class with a list of function pointers. These function pointers point to a member function of a sub-class, which was bound like this: functionList.push_back(std::bind(&SubClass::function, this, std::placeholders::_1, …
veio
  • 507
  • 4
  • 16
1
vote
1 answer

Why aren't placeholders for std::bind implemented using non-type template parameters?

I know the question is rather theoretical but I think if placeholders would be defined as the template like e.g.: namespace std { namespace placeholders { template struct placeholder { constexpr placeholder() {}; }; …
W.F.
  • 13,888
  • 2
  • 34
  • 81
1
vote
1 answer

How std::bind increases number of arguments passed to a function?

I am reading a book, and there is below code : mActionBinding[Fire].action = derivedAction( std::bind(&Aircraft::fire, _1)); the argument that is sent to derived action, will be sent two arguemnts later. template
shayan
  • 361
  • 3
  • 14
1
vote
1 answer

C++ - std::bind call operator() with perfect forwarding

I have to store arguments (parameter pack), and pass the arguments to another function. As a result, I cannot use lambda. And a good choice is std::bind. But for this code struct A{}; void test(A &&){} int main() { A a; test(move(a)); …
Caesar
  • 971
  • 6
  • 13
1
vote
1 answer

C++ bind member functions using pointers

I am trying to understand how std::bind works with member function pointers. So this example is pretty clear to me. #include #include using namespace std::placeholders; struct Foo { void print_sum(int n1, int n2) { …
Bobo
  • 245
  • 2
  • 10
1
vote
1 answer

Using std::bind inside std::for_each

Consider the following snippet: #include #include #include #include #include typedef std::string::size_type StrSize; //Strips the passed symbol from the start and end of the passed source string. void…
Chani
  • 5,055
  • 15
  • 57
  • 92
1
vote
1 answer

Pass std::bind object with bind member function to a function

I want to connect a callback function to a boost signal through a public function. I can pass a function pointer just fine, but if I try to use std::bind to pass a member function, it will not compile. Giving me error saying no viable conversion.…
DXM
  • 1,249
  • 1
  • 14
  • 22
1
vote
1 answer

std::bind argument copying behaviour

Is it safe to pass an std::shared_ptr to std::bind when the function object will be called asynchronously? I.E. Is roughly the following safe: // Copy do not reference shared_ptr void someFunc(std::shared_ptr arg1,...other…
Jarra McIntyre
  • 1,265
  • 8
  • 13
1
vote
1 answer

Type cast std::placeholder

I'm trying to use std::bind and typecast the function arguments to use with a typedef function. However, I can't typecast the std::placeholder. Any ideas to implement what I'm trying to do? For varied reasons, I need to be able to have the typedef…
Mumblepins
  • 21
  • 1
  • 2