std-function Questions
9
Solved
I have a number of callback functions with different signatures. Ideally, I would like to put these in a vector and call the appropriate one depending on certain conditions.
e.g.
void func1(const...
Threescore asked 2/10, 2014 at 10:0
1
I am trying to pass a pointer to the predicate function into the Foo and Bar functions.
The Bar function works correctly, but the Foo function raises a compile-time error:
error: no matching funct...
Kumamoto asked 28/8, 2020 at 10:11
6
Solved
How can I compare two C++11 std::functions with operator==, and return true if both of said functions refer to the same function pointer?
Robinson asked 30/12, 2013 at 4:43
4
Solved
If I need to generate a lambda that calls a member function. Should I capture by reference or capture this? My understanding is that & captures only the members used, but this captures all data...
Elan asked 6/11, 2015 at 20:55
2
Solved
When move-constructing a std::function object from a lambda, where that lambda has by-value captures, it appears that the move-constructor of the object that is value-captured is called twice. Cons...
Procrustean asked 26/6, 2020 at 8:54
2
Solved
I encountered a problem. When I use something like std::function<A(Fs...)> it doesn't work, but std::function<A(Fs..., B)> does work. This is under Clang 8.0; none of it works under GCC...
Sparteine asked 17/4, 2020 at 22:11
6
Solved
As a lazy developer, I like to use this trick to specify a default function:
template <class Type, unsigned int Size, class Function = std::less<Type> >
void arrange(std::array<Type...
Gemmulation asked 4/3, 2013 at 13:16
4
Solved
To set a std::function variable to a lambda function with default argument I can use auto as in:
auto foo = [](int x = 10){cout << x << endl;};
foo();
This will print 10.
But I want...
Asare asked 7/4, 2014 at 15:29
1
Are captured arguments copied during the conversion of lambdas to std::function?
I need to convert a lambda that captures a non-copyable type to std::function.
So I passed a lambda to std::fu...
Infect asked 27/12, 2019 at 1:14
4
Solved
I know that the following code won't compile.
void baz(int i) { }
void baz() { }
class Bar
{
std::function<void()> bazFn;
public:
Bar(std::function<void()> fun = baz) : bazFn(fun){...
Azoth asked 13/12, 2019 at 14:32
1
Solved
Suppose I have a callable type like so:
struct mutable_callable
{
int my_mutable = 0;
int operator()() { // Not const
return my_mutable++;
}
};
Note that mutable_callable has a non-const ope...
Frae asked 4/12, 2019 at 15:21
3
Solved
I was wondering how to properly check if an std::function is empty. Consider this example:
class Test {
std::function<void(int a)> eventFunc;
void registerEvent(std::function<void(int ...
Throckmorton asked 16/2, 2014 at 2:44
2
Solved
An overloaded function should take both functors in, given the type of the lambda is decidable ( castable to an std::function (please correct me if I'm wrong ).
The question is: Why is there a comp...
Muleteer asked 30/10, 2019 at 14:2
2
Solved
Basically, I would like to have the following semantic :
#include <functional>
#include <iostream>
class test
{
public:
void add(std::function<void()> f)
{
f();
}
void op...
Draughtsman asked 20/6, 2014 at 22:55
4
Solved
I'm playing around with callback functions and wish to register multiple functions via std::bind that differ in signatures (altough they all return void). Assigning the result of the std::bind to t...
Furfuran asked 29/8, 2019 at 11:41
1
Solved
Consider the following code snippet:
#include <functional>
namespace ns {
struct Arg{};
using Func = std::function<int(Arg)>;
Func operator+(Func lhs, Func rhs) {
return [lhs, rh...
Oversold asked 14/8, 2019 at 14:17
3
Solved
Here is the problem I am facing: I have an overloaded function in a class, and I want to pass one of its overloads as a parameter. But when doing so, I get the following error :
"no suitable cons...
Contumelious asked 16/7, 2019 at 16:54
3
Solved
Library code:
class Resource
{
public:
typedef void (*func_sig)(int, char, double, void*);
//Registration
registerCallback(void* app_obj, func_sig func)
{
_app_obj = app_obj;
_func = func;
...
Consonance asked 13/1, 2013 at 18:7
2
When generic lambda is stored as a std::function, we need to provide a concrete type, something like,
std::function<double(double)>
thus binding to a specific type,
The following d...
Elimination asked 18/12, 2018 at 8:4
2
Solved
I would like some information on how to correctly think about C++11 closures and std::function in terms of how they are implemented and how memory is handled.
Although I don't believe in premature...
Bespatter asked 30/8, 2012 at 17:50
4
Solved
Why can't I have a std::set or std::unordered_set of std::functions?
Is there any way to get it to work anyway?
Weirick asked 24/11, 2018 at 15:34
3
I was surprised to find this code compiles:
#include <functional>
struct Callable {
void operator() () { count++; }
void operator() () const = delete;
int count = 0;
};
int main() {
co...
Britneybritni asked 30/10, 2018 at 10:49
2
Solved
So in it's most distilled form I have something like this going on,
template <class T>
bool f(const T &a, const T &b, std::function<bool(const T&, const T&)> func)
{
...
Nolasco asked 26/9, 2018 at 1:10
2
I heard that cost of std::function is heavier than auto to deal with a lambda function. effective modern c++ item5. What I want is to clarify the mechanism why std::function use more memory than au...
Roemer asked 28/12, 2017 at 12:26
4
Solved
I am learning functional programming in C++. My intention is to pass a non generic function as argument. I know about the template method, however I would like to restrict the function signature as...
Mauve asked 16/8, 2018 at 9:11
© 2022 - 2025 — McMap. All rights reserved.