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
0
votes
2 answers

C++ weak functor solution

This is specific to void() functors, but that is fine with me... struct Foo { void Bar(int x) { std::cout << x << std::endl; } }; struct VoidBind { typedef void result_type; template void operator()(const…
user1715664
  • 153
  • 2
  • 10
0
votes
0 answers

Visual C++ function and bind problems

I have a class which works with files, the constructor is receiving a std::function for sending the status of the work to a GUI Library if used. Declaration: DASM(std::string filename, std::function f =…
SepGuest
  • 127
  • 1
  • 11
0
votes
1 answer

C++11 std::bind works strange

It's event manager, which work principle shown in the main(). So, the code: class CEventManager { public: static CEventManager *const GetInstance() { static CEventManager pInstance; return &pInstance; }; template…
Aleksey
  • 140
  • 1
  • 8
0
votes
1 answer

c++: How to write a std::bind-like object that checks for superfulous parameters?

According to http://en.cppreference.com/w/cpp/utility/functional/bind, for std::bind Member function operator() ... If some of the arguments that are supplied in the call to g() are not matched by any placeholders stored in g, the unused…
thor
  • 21,418
  • 31
  • 87
  • 173
0
votes
1 answer

Compile error with C++11 std::bind and auto for Callback function parameter

Hi I am having an issue compiling the following code. I am using auto and std::bind to bind a callback function with arguments. However, after passing this callback function as a parameter, it has issues compiling. Do you see an issue with the…
code
  • 5,294
  • 16
  • 62
  • 113
0
votes
1 answer

Got stack overflow when constructing std::function with std::bind result

#include #include void foo(int a, int b) { printf("%d %d\n", a, b); } int main() { using namespace std::placeholders; auto f1 = std::bind(foo, 10, _1); // fine std::function f2 = f1; // fine …
user1429171
  • 165
  • 8
0
votes
1 answer

Can std::bind1st be used to convert void (*)(void*,int) to void (*)(int)?

I have a function void f (void*, int);, that is used as a callback function. The caller expects void (*)(int). Can I use std::bind1st to convert one to another? Is there any way to do this without using C++ 11 std::bind, just std::bind1st?
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
0
votes
0 answers

Does std::bind have boost-like overloaded operators for its result?

Boost has overloaded operators for boost::bind result type. So !bind(f, ...) is equivalent to bind( logical_not(), bind(f, ...) ). Some other operators like ||, && can be used as well. Does std::bind have the same features? Can one use…
Pavel Davydov
  • 3,379
  • 3
  • 28
  • 41
0
votes
1 answer

Can I std::bind a base class' constructor so that the derived doesn't need to call it explicitly?

I have an abstract base class that needs some objects passed to its constructor to initialize its members. But I would like to get rid of passing those objects through the derived class constructor. class Derived : public Base { public: …
danijar
  • 32,406
  • 45
  • 166
  • 297
0
votes
1 answer

in base class, how to define a container to contain function obj which can be any func of derived class?

I want to define a container in the base class, which contains function obj or anything that can make my purpose happen. These function obj can call derived classes' functions. they all take same parameters. #include #include…
doufunao
  • 155
  • 8
0
votes
1 answer

How do I correct returning a local or temporary in this template code?

I'm binding a copy_if into a function object that will accept a pair of iterators. I have a warning that I'm returning a local address or temporary. I've come as far as knoing it comes from binding member variables of an std::pair of iterators, but…
Matthew Reddington
  • 1,409
  • 3
  • 13
  • 24
0
votes
1 answer

The use of std::bind with a binary operation function in C++

I am trying to learn how the std::bind works. I wrote the following: #include #include #include using namespace std::placeholders; int fun2(int i,int j) { return i+j; } int fun(int i) { return i; } int…
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133
-1
votes
3 answers

Why does std::function can implicit convert to a std::function which has more parameter?

I have the following: void print_str(std::shared_ptr str) { std::cout << str->c_str() << std::endl; } int main() { auto str = std::make_shared("Hello"); std::function f = std::bind(print_str, str); …
Griyn
  • 87
  • 8
-1
votes
1 answer

Passing a callable that may change to an instance of a class

I have a set of callables which I'd like to associate to instances of a particular class Node. Each instance of Node needs only hold one callable, and may call it from a member function. Suppose A, B, and C are callables, which may have different…
Turambar
  • 153
  • 11
-1
votes
1 answer

C++ is it possible to bind multiple methods together?

I would like to call a method after another method using std::function. Suppose i have something like this class foo { std::function fptr; void bar(int){ } void rock(){ } public: foo() { fptr =…
James Franco
  • 4,516
  • 10
  • 38
  • 80
1 2 3
24
25