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

How can I make a C++ member function by binding the arguments of another member function?

I am having problems with creating a variable of pointer-to-member-function (PTMF) type "on the fly" (that is, by pinning some arguments of an existing member function via std::bind). My question is if it is ever possible with C++11 or post-C++11…
cheater
  • 39
  • 5
2
votes
5 answers

Store a function with arbitrary arguments and placeholders in a class and call it later

So I am creating a type of event handler and I am in the process of writing an "Event Listener Wrapper", if you will. The basic idea is this: When you want to subscribe to an event, you create a function that should be called when the event fires.…
Dalen Catt
  • 111
  • 1
  • 9
2
votes
1 answer

Perfect forwarding of references with std::bind inside variadic template

I stumbled upon a bug in my code which I traced down to the fact that arguments to std::bind "...are never passed by reference unless wrapped in std::ref or std::cref". What I have I have a function template which looks like this (stripped of…
cantordust
  • 1,542
  • 13
  • 17
2
votes
1 answer

Why does std::bind prevent late binding when using pass-by-reference?

I have a base class, a derived class, and a virtual member function. I also have a function which takes a base class reference and makes a polymorphic call to the member function: #include #include class Base { public: …
andreasdr
  • 3,804
  • 4
  • 28
  • 32
2
votes
1 answer

chained std::bind compile error with VS2015

I'm using VS2015 and I'm playing with std::function and std::bind I found a strange errors. I have a 2 chained bind operation: int main() { auto func1 = [](int i) -> int { return i + 1; }; auto func2 = [](float f,…
dectroo
  • 143
  • 1
  • 9
2
votes
1 answer

Template deduction: porting to C++11

Following code is legal for C++14 compiler // g++ -std=c++14 -pedantic -pthread main.cpp // output: 1 2 3 4 5 1 1 1 #include #include #include #include #include int main() { …
Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42
2
votes
3 answers

How To Combine Multiple std::function To One?

I have multiple std::function. Each of them have different input and output, and the input of one std::function might be the output of another std::function, which means that "serial" convert from one to another. Maybe I can't describe it clear…
Ringo_D
  • 784
  • 5
  • 18
2
votes
1 answer

using std::bind with std::reference_wrapper::get

I'm trying to use std::bind to call std::reference_wrapper::get but I can't get it to compile. I'm sure I'm overlooking something obvious but the compiler errors are not helping me out. This code is contrived and doesn't represent my actual use…
atb
  • 1,412
  • 1
  • 14
  • 30
2
votes
1 answer

Error using std::bind and std::function in C++

I attempt to try my snippet of Newton's method on a multivariate function and used std::bind and std::function. But I was stuck on an error error: conversion from 'std::_Bind_helper&, int>::type {aka std::_Bind, int))(double, double, double)>}'…
Nicholas
  • 2,560
  • 2
  • 31
  • 58
2
votes
2 answers

Force an object to be passed as copy to a function receiving a universal reference

I'm trying to pass a local lambda function to a std::bind (for passing to a connect function of a signal): void f() { auto signal_f = [this](int, int) { /* ... */ }; namespace ph = std::placeholders; signal.connect(std::bind(signal_f,…
ABu
  • 10,423
  • 6
  • 52
  • 103
2
votes
1 answer

std::function to variadic member function and then bind variadic template arguments

I have two variadic class member functions. When the first one Init(...) is called I want to create a std::function to the second class member function and then bind the arguments of Init(...) to the function pointer. So then later on I can just…
2
votes
2 answers

pass a function of an object to another std::function of another class

What is the right way to pass a member function of one class to an std::function of another class? For example, the Bar below wants to store one function of a Foo object. class Foo { public: Foo(int x) : data(x) {} bool isEven(int y) { return…
Solti
  • 633
  • 2
  • 6
  • 17
2
votes
4 answers

Unable to std::bind member function

I've written the following class: class SomeClass { private: void test_function(int a, size_t & b, const int & c) { b = a + reinterpret_cast(&c); } public: SomeClass() { int a = 17; size_t b = 0; …
Xirema
  • 19,889
  • 4
  • 32
  • 68
2
votes
1 answer

std::bind header file declaration

I want to create a std::bind for a function in a cpp file other than my main one, and also in a different namespace. The problem I'm having is how to declare said function in the header file since the binding itself depends on a variable not…
2
votes
1 answer

Error binding make_unique

I'm having trouble using std::bind with std::make_unique. I have an object to whose constructor I pass factory functions for making std::unique_ptrs of objects of another class type. Using VS2013, this works: Tester tester( [](){return…
chili
  • 665
  • 8
  • 20