All Questions
Tagged with function-templates lambda
12 questions
2
votes
2
answers
144
views
Is there a way to pass a function template, as an argument in another function?
The best way for me to describe what I am asking is a simple example.
template<typename T>
void execute_example(T* begin, T* end)
{
T val = 10 * 0.8;
while (begin != end)
{
...
2
votes
3
answers
436
views
Template function cannot recognize lambda referred by an auto variable [duplicate]
In c++17, I have a template function which takes some kind of lambda as input. However it only recognizes those with explicit types and ones using auto are rejected.
Why this is the case and any way ...
2
votes
1
answer
97
views
How to get function template taking invokables to match the types?
I have the following code intended to take a generic function object that takes two arguments and return a function object that does the same with the arguments in the other order.
#include <...
8
votes
3
answers
514
views
Passing a templated function as method argument without lambdas?
I did like to being able to use extFunction or std::max or std::min as argument for the square method without declaring a lambda :
template<typename T>
T extFunction(T a, T b)
{
return a;
}
...
0
votes
0
answers
150
views
lambda as part of a static variable in a template function
Let's say we define a simple struct S containing 2 members (1 int and 1 functor) in a header file. And we create a such struct as a static const variable in a template function foo and return the ...
2
votes
2
answers
86
views
Function Template Instantiated With Runtime Constant
I need some way to combine lambda's ability capture a runtime value and function template's ability to specify any type we want. What is the best way to do it?
Lambda allows us to capture the value ...
0
votes
3
answers
101
views
Function Template with optional argument or overloaded
I got a class, containing 20 structure elements in a classical C-Array. The elements form 0 to 5 belong to Type A, from 6 to 15 they belong to Type B and the rest belongs to Type C.
For looping this ...
-1
votes
3
answers
370
views
Should lambdas replace function templates in C++?
In C++ I can write:
auto sum(const auto& x1, const auto& x2)
{
return x1 + x2;
}
int main()
{
cout << sum(1, 2) << endl;
cout << sum(1, 2.3) << endl;
...
0
votes
1
answer
76
views
Template function which takes lambda with variadic parameters
Educational task: want to write a function which take functional object and its arguments and call it using perfect forwarding:
auto fun = [](std::string a, std::string const& b) { return a += b; ...
2
votes
2
answers
209
views
function overloading with std::function and generic lambdas: std::string preferred over int
When trying to compiling this, suprisingly, it gives an error because the auto parameter of the lambda function has been resolved to std::string, and the compiler doesn't know how to convert std::...
0
votes
1
answer
90
views
How to make std::distance a Callable for apply or invoke?
I played around with C++17/C++1z features apply and invoke a bit
Ultimately I wanted to use apply to the result of equal_range directly
like this:
cout << apply(std::distance, data.equal_range(...
20
votes
3
answers
4k
views
Why doesn't C++11 implicitly convert lambdas to std::function objects?
I implemented a generic event emitter class which allows code to register callbacks, and emit events with arguments. I used Boost.Any type erasure to store the callbacks so they can have arbitrary ...