stdbind Questions
5
Solved
I know what functors are and when to use them with std algorithms, but I haven't understood what Stroustrup says about them in the C++11 FAQ.
Can anyone explain what std::bind and std::function ar...
Wirewove asked 7/7, 2011 at 11:43
3
Solved
This is my code snippet:
class Base {
public:
Base() {
foo();
bind();
}
virtual void foo() {
std::cout << "base foo\n";
}
void bind() {
fn = std::bind(&Base::foo, t...
Sutton asked 25/9, 2023 at 14:10
1
Solved
I have a C++ function that takes a std::function as an input argument.
Specifically, a std::function<void (const Message&, Error)>.
In my use-case, the caller may bind the std::function t...
Gobble asked 26/4, 2023 at 20:10
2
Solved
I cannot find out how to bind a parameter to an overloaded function using std::bind. Somehow std::bind cannot deduce the overloaded type (for its template parameters). If I do not overload the func...
Backandforth asked 21/7, 2014 at 20:49
0
#include <functional>
#include <iostream>
#include <string>
#include <utility>
using namespace std;
template<typename Func, typename... Args>
void do_task(Func ...
Pernambuco asked 22/8, 2022 at 16:1
3
Solved
I have been trying to understand how std::bind works. So working up with different examples. Below is the sample program whose output i am unable to understand.
VERSION 1
class NAME
{
public:
voi...
1
Trying to get the function object from std::bind() using following code:
driver_manager driverManager();
std::function<void(mqtt::const_message_ptr,
mqtt::async_client*,callback*,sql::Dri...
Persse asked 7/7, 2021 at 17:31
1
Solved
I find it very confusing that the following code fails to compile
#include <functional>
class Mountain {
public:
Mountain() {}
Mountain(const Mountain&) = delete;
Mountain(Mountain&am...
Maggard asked 19/5, 2021 at 10:38
4
Can someone recommend some cool practical uses of tr1's mem_fn and bind utilities? I don't need esoteric c++ for library development. just some application level coding which makes uses of these.
...
3
Is there a way to partially bind the first/last n arguments of a callable object (e.g. function) without explicitly specifying the rest of the arguments?
std::bind() seems to require that all the...
Zerk asked 19/1, 2014 at 12:29
2
Solved
As mentioned in a similarly worded question (Why use bind over lambdas in c++14?) The answer was - no reason (and also mentioned why it would be better to use lambdas).
My question is - if in C++14...
Cost asked 9/7, 2020 at 5:2
2
Solved
#include <iostream>
#include <functional>
using callback = std::function<void(int, void*)>;
void AddCallback(callback cb) {}
void foo(int i) {}
int main() {
auto f = std::bin...
2
Solved
I have several functions with almost identical signatures (made much shorter than actual code):
int hello(A a, B b, C c, int n);
int there(A a, B b, C c, int n);
int how(A a, B b, C c, int n);
int...
4
Let's assume I want to pass a function object created by std::bind by reference to a funktion:
void myCallback(int i, int j)
{
std::cout << "toCall , i=" << i << " j=" << ...
Ecthyma asked 28/1, 2020 at 21:21
2
Solved
I am using the following code to add signal handling to my C++ classes:
namespace {
std::atomic<bool> signal_flag(false);
}
void terminate_or_interrupt_handler(int signal) {
switch (signa...
1
Solved
I am playing around with std::function and std::bind to understand how arguments are copied around and if I can save some of the copy operations.
I understand that when using std::bind, the argum...
Klee asked 27/5, 2018 at 5:6
4
Solved
I wonder how the following can be done
void f(string &&s) {
std::string i(move(s));
/* other stuff */
}
int main() {
std::string s;
bind(f, s)(); // Error.
bind(f, move(s))(); ...
Erzurum asked 26/2, 2011 at 9:55
2
Solved
For example, this is my member function (do_it):
class oops
{
public:
void do_it(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_print ("Hi there :)\n");
}
};
... and i use std::bind ...
2
I have api function f_api(std::function<void(int)> func) and now I have my process class
class Func {
public:
void operator()(int i) {
// do some work
}
int operator()(int i, int j) {
/...
3
Solved
I want to implement a manager that stores callbacks to member functions of polymorphic classes using C++11. The issue is that I am not sure how to handle the case where the object that the member b...
Cordwood asked 21/12, 2015 at 14:19
1
Solved
To create std::function, here is what I do:-
std::function<void(int,int,int)> f =
std::bind(&B::fb,this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3
);
void...
Trinitrobenzene asked 31/7, 2016 at 5:4
2
Solved
I'm working with std::bind but I still don't get how it works when we use it with member class functions.
If we have the following function:
double my_divide (double x, double y) {return x/y;}
...
2
I'm confused as to why std::mem_fn is needed.
I have a function that takes in any callable (lambda, function pointer, etc),and binds it to an argument.
Eg:
template<class T>
void Class::Do...
1
Solved
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...
Bulwark asked 28/3, 2016 at 13:14
3
Solved
I am using GCC 4.6.3 and was trying to generate random numbers with the following code:
#include <random>
#include <functional>
int main()
{
std::mt19937 rng_engine;
printf("With b...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.