std-function 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
7
Solved
According to the sources I have found, a lambda expression is essentially implemented by the compiler creating a class with overloaded function call operator and the referenced variables as members...
Essayist asked 26/8, 2013 at 21:16
6
Solved
I can easily bind member functions to a std::function by wrapping them with a lambda expression with capture clause.
class Class
{
Class()
{
Register([=](int n){ Function(n); });
}
void Regi...
Transpacific asked 16/6, 2013 at 9:17
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
3
I discovered that compile time of a relatively small amount of code, converting lambda functions to std::function<> values, can be very high, in particular with Clang compiler.
Consider the ...
Perpetua asked 25/9, 2018 at 13:15
4
Solved
I'm trying to bind some ta-lib functions and then callback.
Here is the simplified sample code:
#include <functional>
#include <type_traits>
#include <cstdint>
struct DataChunk {...
Snappish asked 13/2, 2023 at 9:13
1
Solved
In libc++'s implementation of std::function, if the function object whose type is being erased is small enough to fit inside an SBO then the move operation will copy it, not move it. Yet not every ...
Auklet asked 11/1, 2023 at 12:4
1
I have a member function with a variable number of parameters, stored in a std::function, and I want to bind the instance and get an independent function object.
template <class T, class R, cla...
Herbie asked 10/8, 2012 at 13:36
2
Solved
Since std::function can hold member functions, so it must store a pointer to the object instance somewhere.
How can I fetch the this pointer from a std::function that holds a member function?
Marielamariele asked 1/4, 2013 at 16:53
2
Solved
A lambda can be easily converted to std::function though this seems to be impossible when the lambda uses generalized capture with a unique_ptr. Likely an underlying std::move is missing. Is there ...
Sowell asked 15/11, 2022 at 15:23
2
Solved
std::function is known to have performance issues because it may do heap allocations. Admitted, if you are being 100% honest, one heap allocation should hardly be a problem in most cases... but let...
Pulchia asked 11/2, 2016 at 16:59
2
Solved
I want to make a simple logger which automatically runs a function and returns its value.
The class is defined as:
template <typename R, typename... Args>
class Logger3
{
Logger3(function&l...
Scourge asked 26/7, 2022 at 5:31
3
Solved
Consider the following class:
template <class T>
struct Test
{
Test() {
if (!f) {
f = []() { std::cout << "it works\n"; };
initialized = true;
}
}
static void check() {...
Streaming asked 23/7, 2022 at 10:58
3
Solved
It is necessary for me to use std::function but I don't know what the following syntax means.
std::function<void()> f_name = []() { FNAME(); };
What is the goal of using std::function? Is it...
Truculent asked 3/12, 2013 at 14:2
2
Solved
I want use a std::function in std::map, follow the code:
#include <functional>
#include <map>
class MyClass {
...
std::function<void()> Callback();
std::map<std::string, C...
Fossil asked 21/3, 2015 at 15:29
2
Solved
I have a struct with a method called call which has a const overload. The one and only argument is a std::function which either takes a int reference or a const int reference, depending on the over...
Vociferant asked 8/4, 2022 at 12:29
1
Solved
Many topics told us that use small object like lambda expression could avoid heap allocation when using std::function. But my study shows not that way.
This is my experiment code, very simple
#incl...
Brita asked 5/1, 2022 at 9:3
3
Solved
The following code works, but I feel that the line worker([this](int a, long b, int* c){receiver(a, b, c);}); is sort of redundant because it is repeating the signature of receiver. Instead of pass...
Jae asked 4/12, 2021 at 20:40
3
Solved
I have a function that needs to get std::function-type parameter. I also have an abstract-type pointer to an object. Is it possible to pass the method using only an object?
The function signature:...
Trula asked 19/4, 2019 at 16:51
6
Solved
Can lambdas be defined as data members?
For example, would it be possible to rewrite the code sample below using a lambda instead of a function object?
struct Foo {
std::function<void()> bar...
Strata asked 6/7, 2011 at 19:37
1
Solved
C++23 introduced std::function's cousin std::move_only_function, just like its name, it is a move-only wrapper for move-only callable objects (demo):
#include <functional>
#include <memory...
Hammers asked 9/10, 2021 at 17:52
1
Solved
#include <functional>
void toggleOk(bool& b) { b = !b; }
void toggleBroken(bool b) { b = !b; }
void toggleInt(int i) { i = !i; }
void tooManyParams(bool b, int i) { i = !b; }
int main()...
Destinee asked 29/8, 2021 at 8:16
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
8
Solved
Thanks to C++11 we received the std::function family of functor wrappers. Unfortunately, I keep hearing only bad things about these new additions. The most popular is that they are horribly slow. I...
Royroyal asked 3/2, 2013 at 22:21
3
Solved
Consider this pseudo-snippet:
class SomeClass
{
public:
SomeClass()
{
if(true)
{
fooCall = [](auto a){ cout << a.sayHello(); };
}
else
{
fooCall = [](auto b){ cout << b.sayHel...
Downcast asked 16/11, 2017 at 14:32
1 Next >
© 2022 - 2024 — McMap. All rights reserved.