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

how to use touchAttachInterrupt with member function of a class as a callback function

Class A { public: A(); void onTouch(); } A::A() { touchAttachInterrupt(1, std::bind(&A::onTouch, this), 40) } This does not works for me with ESP32. The definition of the touchAttachInterrupt is: void touchAttachInterrupt(uint8_t pin, void…
Priyank Bolia
  • 14,077
  • 14
  • 61
  • 82
0
votes
0 answers

Attach callback function without `std::function`

Issue: I have std::vector to store callback. callback_func_t is void(*)(void*) void add_func(callback_func_t fn) is mathod to attach/add callbacks to vector using .push_back mathod. Here is my demo code snippest. I want to attach…
0
votes
0 answers

std::bind a member function at "top-level"

I figured I could initialize a type that takes a callable with std::bind to a member function at top level. However, I seem to make a mistake. I just can't point my fingers where. Compiler errors seem pretty arbitrary... Demo #include…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
1 answer

Error while binding telnet_event_handler_t using std::bind

I am trying to design telnet-client.c in CPP. While initializing the telnet client, an event handler having the structure telnet_event_handler_t must be passed as shown below (see implementation here): static void _event_handler(telnet_t *telnet,…
ravi
  • 6,140
  • 18
  • 77
  • 154
0
votes
1 answer

Problem using std::transform with lambdas VS std::transform with std::bind

I am using Clang 14.0.0 and C++20. My goal is to write a general function in order to use std::lerp on a set of elements. So I came up with this: template constexpr…
Luigi Castelli
  • 676
  • 2
  • 6
  • 13
0
votes
0 answers

Multithreading using std::bind - Unsure how to pass parameters

process_data.h: void computeAvgFactor(const int*, int, int, double&); void computeVarFactor(const int*, int, int, double, double&); class ProcessData { int total_items{}; int* data{}; int num_threads{ 0 }; // to hold…
0
votes
1 answer

Why can std::function bind functions of different types?

I saw a special usage about std::bind(), just like the following code: using namespace std::placeholders; class Test { public: Test() { _state_function_map[0] = std::bind(&Test::state_function, _1, _2); } void test_function() { …
tanghz
  • 13
  • 2
0
votes
2 answers

How can I store a std::bind function pointer?

Here is the code I am using #include #include #include class Context { private: std::thread thread; bool running; void run() { while (running) { if (function != nullptr) { function(); …
LiteApplication
  • 177
  • 2
  • 13
0
votes
0 answers

VS15 gives warnings but compiles std::function instantiated with std::bind

I've been trying to figure out how to properly instantiate a vector of std::pairs of std::functions (e.g. std::vector, std::function>>). Upon doing so however, Visual Studios 15 gives me a red underlining…
0
votes
0 answers

What happens when call a pointer to data member with arguments

From Cppreference, I found it noted that Pointers to data members are Callable, even though no function calls take place. However, when I test following code #include #include using namespace std; class CTest { public: …
0
votes
0 answers

std::bind causes "failed to specialize function template" error on MSVC

As a bit of context on the issue I have, I am trying to compile my project using MSVC (Visual Studio 2022) on Windows and it produces a bunch of errors, which is surprising, considering the same code builds just fine on GNU-G++. What I am trying to…
Adrian Costin
  • 418
  • 3
  • 12
0
votes
2 answers

How to use lambdas to use std::function with member functions?

I'm trying to move some global functions inside a class. The current code looks like this: struct S{}; void f(S* s, int x, double d){} void g(S* s, int x, double d){} /* ... ...*/ void z(S* s, int x, double d){} int main() { function
vmp
  • 2,370
  • 1
  • 13
  • 17
0
votes
1 answer

error error: no type named 'type' while calling ioService()->post(std::bind(some argmumet)

class LogSyslogTest{ using LogSyslogCbFn = std::function; static void v4Handler(const LogSyslogHdr& logSyslogHdr, const Ipc::Ipv4& ipv4, const Layer4Bytes& l4Bytes, CbFn fn) { …
sanky
  • 131
  • 1
  • 1
  • 8
0
votes
1 answer

How to pass a std::function callback to a function requiring a typedef of a pointer to a function

I've got a C library that takes a function pointer to register commands. I want to use this in my C++ application. I've tried to use std::function in combination with std::bind to create a C compatible function pointer that will call my member…
WesleyE
  • 1,384
  • 1
  • 12
  • 29
0
votes
2 answers

Run time choice of method using std::bind. Problem with access to variable

I need to choice the particular method of the class at the run time. To do it I use std::bind. Below is an example demonstrating what I do: #include #include class bc { public: bc(int, double); …
Roman Fursenko
  • 688
  • 4
  • 9