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

Bind std::function error

I face a problem when trying to bind a method with std::function and std::bind. In my CommunicationService class : this->httpServer->BindGET(std::bind(&CommunicationService::ManageGETRequest, this,…
Morgan
  • 476
  • 9
  • 23
3
votes
2 answers

Using std::bind to bind parameters and object instance separately

Is it possible to bind arguments to a member function call, and later bind the target object separately? What I was trying to achieve is a helper function which receives a function with arbitrary arguments as an argument, and then executes it on all…
Zepee
  • 1,640
  • 3
  • 20
  • 40
3
votes
1 answer

std::bind with overloaded function from parent class

#include #include class Base { public: virtual ~Base() {} virtual void f1() const {std::cout<<"Base::f1() called"<
qdtang
  • 31
  • 5
3
votes
1 answer

How to bind a member function to an object in C++14

I am trying to bind a member function to an object while keeping the arguments open. I know I can do it by wrapping it in a lambda expression (like this) but I want to use std::bind and std::placeholders to do it. So far this is what I've…
geanakuch
  • 778
  • 7
  • 13
  • 24
3
votes
4 answers

Is it possible to accept the output of `std::bind` directly as a value, without conversion to std::function?

This answer states that std::bind returns an object by value, and this comment implies that assigning to std::function will cause a heap allocation to store the value returned by std::bind. Is there a way to avoid this heap allocation and pass the…
merlin2011
  • 71,677
  • 44
  • 195
  • 329
3
votes
1 answer

Different overloads with std::function parameters is ambiguous with bind (sometimes)

I have two overloads of a function foo which take different std::functions which results in an ambiguity issue for the latter when used with the result of a std::bind. I don't understand why only this is ambiguous. void…
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
3
votes
3 answers

In C++11, is it possible to wrap a template function in a std::function?

If i have a template function in C++11, is it then possible to wrap it in a std::function? My problem is like this: I have a generic function (say a sum function) where the return type depends on the types of the arguments: template
AcId
  • 458
  • 2
  • 12
3
votes
3 answers

Alterantive for callbacks using std::function

Currently I am trying out a code that does essentially the following: void f(int x) { cout << "f("<
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
3
votes
1 answer

How to use template function parameter in std::bind?

i am trying to create a function that parallelize a for. I am using the Thread of the SFML and std::bind with template. Here is what i tried. #include #include #include sf::Mutex mutex; template
Xotraz
  • 33
  • 1
  • 4
3
votes
3 answers

Is it safe to change a function pointers signature and call it to ignore the return type?

In our codebase we have callbacks that are stored using (eg. std::function). Sometimes we would like to bind a function with a different signature to the callback which can be done using bind. This is fine for different function parameters…
fun4jimmy
  • 672
  • 4
  • 16
3
votes
1 answer

How can I avoid this code duplication?

I have two methods which have almost the same code except for two methods they call (and some other details I can easily parameterize). However, those method calls have the same signature, so I think I can generalize them into a single method. class…
dario_ramos
  • 7,118
  • 9
  • 61
  • 108
3
votes
1 answer

Why std::bind can't be param of parameters pack?

I'd like to use parameters pack, but find the problem. Some code: template auto f(Function func, Args... args) -> decltype(func(args...)) { auto f11 = std::bind(func, args...); f11(); } void print(const…
user1733773
  • 360
  • 2
  • 14
3
votes
1 answer

Parallel of std::reference_wrapper for std::shared_ptrs

If you want to bind a reference to a function f, you can use std::bind(f, std::ref(x)). In this case f takes a reference or makes a copy. Now I have a function void g(T & t). I would like to bind the input argument to std::shared_ptr mySharedPtr…
Elliot Cameron
  • 5,235
  • 2
  • 27
  • 34
3
votes
1 answer

Qt and std::bind

I'm trying to use std::bind in Qt 5.1 and MSVC 2010 to hook a QNetworkReply event to a member function while passing the reply as a parameter. Directly putting the std::bind in the connect line fails with a ton of template errors on MSVC 2010 but…
3
votes
1 answer

std::bind, this and QtConcurrent

Im trying to use std::bind to bind this to method that is used in QtConcurrent::blockingMapped Header: class TuringMachine { private: TRTable table; std::set currentConfigs; //function object …
TeaOverflow
  • 2,468
  • 3
  • 28
  • 40