Questions tagged [std-invoke]
11 questions
5
votes
1 answer
Can this member function selection code be written without std::invoke?
I was trying to select a member fn based on some constexpr value. I then tried to call the selected function, but I was getting errors about how I am calling member fn with incorrect syntax.
error: must use '.*' or '->*' to call pointer-to-member…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
4
votes
1 answer
C++: does std::invoke need perfect forwarding?
Snippet
template
auto invokeTest(CallableType&& fn, Args&&... args)
{
return std::invoke(fn, std::forward(args)...);
}
Is std::forward needed here?
Or is it enough to write
template…

Juergen
- 3,489
- 6
- 35
- 59
2
votes
1 answer
std::invoke does not like variadic template member functions?
I am trying to call a variadic function template using std::invoke() and std::apply().
And I apologize ahead of time, because I'm basically dropping a snippet of code here and asking someone to help me understand the error messages to solve the…

user5406764
- 1,627
- 2
- 16
- 23
1
vote
1 answer
Invoke a method for each alternative in a list of std::variant without macros
I have a set of Writer classes each with a different implementation.
I have a list of writers that offers the same interface. Calling a method on the list should invoke the same method on each of the elements in the list (composite design pattern).…

doxygen
- 14,341
- 2
- 43
- 37
1
vote
1 answer
Using std::invoke when a function is overloaded
I am trying to use std::invoke() with an overloaded function:
#include
#include
struct S {
void foo(int) { }
void foo(int, int) { }
};
int main()
{
S s;
std::invoke(&S::foo, s, 1);
}
but I get an error:…

Michal
- 627
- 3
- 13
0
votes
1 answer
Custom callback function cannot take overloads
I have the following class for building callback functions to any subset of function type, be it static function, lambda, lambda w/ capture list, static class functions or member class functions. Problem is that it doesn't take overloads because…

FatalSleep
- 307
- 1
- 2
- 15
0
votes
1 answer
Are value categories preserved inside a tuple (perfect forwarding through tuples)?
I wrote the following snippet to test if I could perfectly forward values through a tuple and std::invoke. However the generated assembly looks kind of odd.
Demo
#include
#include
#include
#include
#include…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
How can I pass a member function pointer type to a template?
I am trying to delegate a method call using a nested std::invoke. Sample code:
class Executor
{
public:
bool Execute(bool someFlag);
};
template
class Invoker
{
public:
TResponse…

pathkon
- 33
- 7
0
votes
2 answers
std::invoke with ref qualifiers
I'm running into the following issue when using ref qualifiers with operator() below. What is the correct syntax to enable the l-value ref overload in this instance?
#include
struct F {
void operator()() & {}
void operator()()…

user3882729
- 1,339
- 8
- 11
0
votes
0 answers
SonarLint: "std::forward" should only be called on a forwarding reference
By analyzing some code using SonarLint, I saw it complaining about the second parameter (Args... args) of the function below. It says:
"std::forward" should only be called on a forwarding reference.
link to the documentation
Here is my…

digito_evo
- 3,216
- 2
- 14
- 42
0
votes
0 answers
Is there a std::invoke-alternative in C++14?
As stated in an answer to this question, std::invoke handles calling not just of simple functions but also other callable types.
Unfortunately I am currently constrained to C++14 - so does anyone know of a C++14 compatible alternative?
My…

JohannesWilde
- 56
- 4