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

Why can I std::bind successfully with the wrong parameters?

#include #include using callback = std::function; void AddCallback(callback cb) {} void foo(int i) {} int main() { auto f = std::bind(&foo, std::placeholders::_1); AddCallback(f); } I tried the code…
Xingx1
  • 127
  • 7
7
votes
2 answers

How to use std::bind function as a signal handler in C++?

I am using the following code to add signal handling to my C++ classes: namespace { std::atomic signal_flag(false); } void terminate_or_interrupt_handler(int signal) { switch (signal) { case SIGTERM: …
motam79
  • 3,542
  • 5
  • 34
  • 60
7
votes
2 answers

How to indicate the overloaded function of given signature in std::bind?

I have api function f_api(std::function func) and now I have my process class class Func { public: void operator()(int i) { // do some work } int operator()(int i, int j) { // do some other work } }; and I…
Liu Weibo
  • 434
  • 5
  • 16
7
votes
1 answer

std::bind and perfect forwarding

The following code does not compile: #include template void invoke(Args&&... args) { } template void bind_and_forward(Args&&... args) { auto binder = std::bind(&invoke,…
Igor R.
  • 14,716
  • 2
  • 49
  • 83
7
votes
2 answers

How do I store a vector of std::bind without a specific case for the template?

After going though a question on std::bind, I was wondering if it was possible to hold a vector of functions created by std::bind so I can avoid using std::function and its heavyweight wrapping. #include #include #include…
CinchBlue
  • 6,046
  • 1
  • 27
  • 58
7
votes
1 answer

Standard method for determining the arity and other traits of std::bind() result?

I've been pounding my head for a few days trying to figure out how to make a class have a nice clean public interface to perform registration of callback mechanisms. The callbacks can be C++11 lambdas, std::function,…
7
votes
2 answers

How do I bind a member function template passing unspecified call wrapper

I tried to compile the following example using VC11 and g++ 4.7.2: #include class X { public: template explicit X(T t) { std::bind(&X::invoke, this, t)(); } private: template void invoke(T…
orlin
  • 73
  • 1
  • 5
7
votes
2 answers

How to do this with std::bind?

(Note: As should already be clear from the tags, this is strictly C++03. Yes, I know, lambda makes all this pain go away (and brings in new kinds, I bet), but this is an embedded system, with an OS version from the 90s, and I am told I should be…
sbi
  • 219,715
  • 46
  • 258
  • 445
6
votes
1 answer

std::bind to std::function conversion problem

Trying to get the function object from std::bind() using following code: driver_manager driverManager(); std::function fn = std::bind(&driver_manager::test_callback,…
6
votes
1 answer

Binding to privately inherited member function

I'd like to std::bind to a member function from a private base class, made "public" with a using-declaration in the derived class. Calling the function directly works, but it seems binding or using member function pointers doesn't compile: #include…
Anders Johansson
  • 3,926
  • 19
  • 19
6
votes
3 answers

std::bind and function templates

I am currently trying to use std::bind to create a std::function from the function template template void printRange(Iterator first, Iterator last) { std::copy(first, last, std::ostream_iterator
Marcel
  • 616
  • 1
  • 5
  • 15
6
votes
1 answer

Why should bind() be deprecated?

Reading the proposal for C++17 about removing some deprecated, old and unused parts of the standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4190.htm) i find section D.9 a bit strange: D.9 "Binders" [depr.lib.binders] This defines…
Martin G
  • 17,357
  • 9
  • 82
  • 98
6
votes
5 answers

Creating a function alias

EDIT: This question was originally titled "Using std::bind to create inline function," but that's not really what I'm after: I just want a simple way to alias functions. I would like to expose std::chrono::high_resolution_clock::now as a standalone…
Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
6
votes
2 answers

Should I be seeing significant differences between std::bind and boost::bind?

I'm exploring the support for C++11 on the g++-4.7 (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. In particular, if I comment out #include and systematically replace occurrences of…
BD at Rivenhill
  • 12,395
  • 10
  • 46
  • 49
6
votes
1 answer

Moving from boost::bind to std::bind: Compile error

I had this code building and running perfectly: boost::function bar = boost::bind(&Bar::BarHandler, this, _1); //Somewhere else in Bar.cpp void Bar::BarHandler( std::string message ){ //Do stuff } When I happily changed boost by…
dario_ramos
  • 7,118
  • 9
  • 61
  • 108
1 2
3
24 25