382 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
5
votes
1
answer
184
views
How to `bind_front()` the `this` pointer in a member function?
I'm writing an async, callback-heavy program, and a common pattern I encounter is, in a member function, having to make a callback pointing to another member function.
What I have so far is this:
void ...
1
vote
1
answer
51
views
How to pass a pointer to member function to a template function
Here is my simplified code: S.h
class SBase {
...
public:
virtual std::vector<int32_t> getNumbersSet1();
virtual std::vector<int32_t> getNumbersSet2();
}
class SDerived : public ...
1
vote
0
answers
73
views
"Preloading" a partial set of args into a variadic function [duplicate]
Objective
I'm attempting to wrap a variadic function so I can provide an arbitrary set of arguments now and provide the rest later.
Ultimately, I want to be able to do something like this:
template<...
0
votes
3
answers
274
views
Using std::bind, Lambda function or alternatives to pass a callback function in c-style to external dll
I want to handover a class member as a callback function in C-style to an external DLL.
What I got so far:
void MyCallback(double a, unsigned char b, unsigned char* c)
{
// do something
}
The DLL ...
3
votes
1
answer
92
views
Derived class member function not implicitly converted to base class member function
In the following code, there are generic classes reg and regmap and a user-defined class mymap which is derived from the regmap class.
In the mymap class, the user creates instances of reg and ...
0
votes
0
answers
108
views
Static C++ check for pure virtual functions passed in constructor to std::bind?
C++ compilers warn if pure virtual functions are directly called in a constructor/destructor (but not indirectly).
Binding a pure virtual function and storing the result in a class member and calling ...
0
votes
0
answers
65
views
How to std::bind a function that in turn calls std::bind?
I thought I had a hold on std::bind, but the compiler has me stumped on this one. Currently compiling with c++17.
I have a generic way of binding a function to a bunch of arguments so that it can be ...
2
votes
0
answers
164
views
Why can't I std::bind_front a function to std::apply?
What if I have a range of pairs and I want to generate a new range from the reduction of those pairs? So my overly "std::" loving brain thought of this:
auto vec_of_pairs = std::vector {
...
-1
votes
1
answer
82
views
mem_fn, bind, function difference when passing parameters
As shown in the code and output below, three phenomena can be observed:
For mem_fn, which is f1 in the code, whether it is passed ff or &ff, the num_ value in the ff object can be modified ...
0
votes
2
answers
278
views
Can I compose functions using std::bind*?
I'm playing with functional programming in C++20 and write something like that:
template <class OuterFn, class InnerFn, class... Args>
concept Composable =
std::invocable<OuterFn, std::...
4
votes
2
answers
158
views
Is there a way to access arguments stored in the function object returned by std::bind() in C++?
I need a way to decompose the function object returned by std::bind() to its arguments in a function template.
The code snippet below shows what I'd like to do:
#include <iostream>
#include <...
7
votes
3
answers
185
views
Why does invoking a virtual method in constructor and binding a virtual method then calling it later yield different results?
This is my code snippet:
class Base {
public:
Base() {
foo();
bind();
}
virtual void foo() {
std::cout << "base foo\n";
}
void bind() {
fn = std::bind(&...
1
vote
1
answer
323
views
Why does bind_front/bind_back/not_fn/bind require Args... to be move-constructible?
I noticed that the std::bind_front/std::bind_back/std::not_fn that yields the perfect forwarding call wrapper all require that the function argument and argument arguments passed in must be move-...
1
vote
1
answer
110
views
std::bind behaves differently when passed a pointer vs reference
The goal is to get a functor to the Base::Print.
#include <functional>
#include <iostream>
using namespace std;
class Base {
public:
virtual void Print() {
cout << "...
1
vote
2
answers
282
views
Bind pure virtual method
Suppose we have the following hierarchy:
class Add3Interface {
virtual int add3 (const int&) const = 0;
};
class Add3: public Add3Interface {
virtual int add3 (const int& arg) const ...