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

Runtime error when using std::bind

The following code compiles and runs successfully on OS X using Xcode 6.3.2. However, it crashes when run on Windows using VS2013. #include #include #include #include #include void validate(const…
ksl
  • 4,519
  • 11
  • 65
  • 106
1
vote
3 answers

rebind one parameter of std::function

In my C++ project I decided to give the new++ features a try. One of those features is the binding of a function with std::function via std::bind. Now I came to a use case, where I have to rebind the std::function. Consider the following simplified…
Timm
  • 1,005
  • 8
  • 20
1
vote
1 answer

g++ error: ‘placeholders’ is not a namespace-name using namespace std::placeholders;

I am trying to understand std::bind.I have written the following program. #include
liv2hak
  • 14,472
  • 53
  • 157
  • 270
1
vote
1 answer

How to use std::bind with lambda

I am trying to use std::bind within my lambda: #include #include #include struct Foo { Foo() {} void func(std::string input) { std::cout << input << '\n'; } void bind() { …
peterphonic
  • 951
  • 1
  • 19
  • 38
1
vote
2 answers

test std::function validity after bind to member function

For the struct: struct A { int var = 10; void check() { std::cout << "var is " << var << std::endl; } }; Say I create a std::function object of A::check(), using a dynamically allocated a object: auto a_ptr =…
badger5000
  • 650
  • 7
  • 17
1
vote
1 answer

C++14 tuple type indexing fails on inferred type from std::bind that I want to be std::function

I am getting an error when using template type deduction combined with C++14 std::get<> with type indices. The code might look a little complex, but I've tried to whittle it down to the bare basics of what's going on. It's really just an Observer…
user5406764
  • 1,627
  • 2
  • 16
  • 23
1
vote
2 answers

How to std::bind a smart pointer return method?

So I have this method inside my Bar class: std::shared_ptr Bar::getStuff() const { //... } And I have my callback typedef: typedef std::function Callback; void Foo::registerCallback(const Callback& callback) { …
waas1919
  • 2,365
  • 7
  • 44
  • 76
1
vote
1 answer

Storing a std::function that includes std::placeholders in an object

I'm trying to write some code that will store a function (with a parameter) as an object member so that I can call it later in a generic fashion. Currently my example uses std::function and std::bind. #include class DateTimeFormat { …
deadpickle
  • 115
  • 2
  • 15
1
vote
1 answer

Template function taking any functor and returning the type of the functor return

I have an member function, which receives some data from serial port and few parser functions in the same class, which then parse recieved data to specific format. All the parse functions take same parameter. What I want is to pass any kind of…
1
vote
1 answer

Using std::bind to capture a parameter pack "by move"

I'm attempting to implement std::async from scratch, and have run into a hiccup with arguments of move-only type. The gist of it is, C++14 init-captures allow us to capture single variables "by move" or "by perfect forwarding", but they do not…
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
1
vote
1 answer

Segfault in std::function destructor

I'm currently maintaining a C++ REST Server developed in C++. It provides some features like middleware and routes. Routes are stored inside an inner structure of the router class: //! The http router //! //! allow us to parse route on a server…
Simon Ninon
  • 2,371
  • 26
  • 43
1
vote
0 answers

std::bind as argument to another std::bind and type inference

Please consider the following code snippet: #include #include typedef std::function doubleFunc; double add(doubleFunc a, doubleFunc b) { return a() + b(); } double constValue(double value) { return…
Kuba Wyrostek
  • 6,163
  • 1
  • 22
  • 40
1
vote
1 answer

std::bind(): bind lambda with rvalue reference as argument

I am playing with std::bind and rvalue references, but I still don't figure out how it works, I have the following code: class Dog { public: Dog(const string &name) : name_(name) { cout << "Dog::ctor" << endl; } string GetName() { …
neevek
  • 11,760
  • 8
  • 55
  • 73
1
vote
1 answer

C++ functional: bind classes method through pointer

I tried to bind a classes method from another class which is storing the first one's pointer, but it always gives me different value. What am I doing wrong? If I pass class A by value (and of course modify class B to store by value) it's…
1
vote
1 answer

std::bind with template member function

I have a strange problem that I cannot bind this template member function, all this code compiles: http://ideone.com/wl5hS8 It's a simple code: I have a ExecutionList which should hold callable functions in a std::vector. I can now add functions by…
Gabriel
  • 8,990
  • 6
  • 57
  • 101