Questions tagged [generic-lambda]

Generic Lambda lets Lambda function parameters be set to auto to let the compiler deduce the type. This generates a lambda type with a templated operator() so that the same lambda object can be invoked with any suitable type and a type-safe function with the right parameter type will be automatically generated.

Generic Lambda lets Lambda function parameters be set to auto to let the compiler deduce the type. This generates a lambda type with a templated operator() so that the same lambda object can be invoked with any suitable type and a type-safe function with the right parameter type will be automatically generated.

More Info : https://en.wikipedia.org/wiki/C%2B%2B14#Generic_lambdas

& https://isocpp.org/wiki/faq/cpp14-language#generic-lambdas

114 questions
0
votes
1 answer

Returning a generic lambda expression from a function causes compiler warnings if an explicit return type is given

I have a function whose return type is a simple generic lambda expression. (The lambda returned by this function is eventually passed as an argument to STL algorithms like std::transform() or std::accumulate().) When the lambda does not have an…
NKatUT
  • 429
  • 3
  • 10
0
votes
1 answer

How to make a class template that wraps a function in a noexcept-detectable, callable object, to use as a std::unique_ptr custom deleter?

Is it possible to use object type and free functions as parameters for creating custom deleters for std::unique_ptr ? I'm new to templates and came up till here: #include template struct ObjectDeleter { …
puio
  • 1,208
  • 6
  • 19
0
votes
2 answers

Java Lambda to Method

Given that I know little and nothing about java, exactly like my English, I have a problem, I have this line of code and I had to delete the lambdas. return articles (args -> {}, queryDef); I used Android Studio, (Alt Enter) and it creates…
LuigiB
  • 43
  • 5
0
votes
0 answers

A static method as a method parameter (as a lambda)

I would like to have a constructor of class to have a lambda as a parameter: class MyComboBox : public QComboBox { public: explicit MyComboBox( const std::function< QString( Flag ) > &readable, QWidget *parent = nullptr ); }; I have some flags in…
Denis Rouzaud
  • 2,412
  • 2
  • 26
  • 45
0
votes
3 answers

Lambda function returned - trying to understand what this means

In a simple example of CommandLineRunner from within the main method of a Spring Boot Application class. Trying to understand the effect/meaning of return args-> lambda function in the run method. The method should return the instance of the…
user1385969
  • 195
  • 2
  • 2
  • 11
0
votes
3 answers

How to Dynamically create Expression> for count and group by clause

I need to create dynamic lambda expression predicate for below query to query in Cosmos DB. *select City, COUNT(City) as CityCount FROM Cities where status="Active" group by City* Earlier I have created for equal operation like this var parameter =…
0
votes
0 answers

c++ generic lambda of template class with abstract parent

I have the following situation: template class Derived { public: T m_Data; }; And I need to store them in std::vector so I've introduced an abstract parent class like so: class Base { public: virtual unsigned int GetID() const =…
Jorayen
  • 1,737
  • 2
  • 21
  • 52
0
votes
2 answers

Inner working of lambda functions when wrapper function is called recursively

Consider the following code: int foo() { int lf = [/*captures*/]() {/*body*/}; if(/*some condition*/) { return /*value*/; } foo(); //recursive call } Now, in this code, whenever the function foo is called recursively, an activation…
user13120769
0
votes
1 answer

Sentiment analysis with Lambda Expressions in Python

I'm trying to use TextBlob to perform sentiment analysis in Power BI. I'd like to use a lamdba expression because it seems to be substantially faster than running an iterative loop in Power BI. For example, using Text Blob: dataset['Polarity…
coolhand
  • 1,876
  • 5
  • 25
  • 46
0
votes
2 answers

Using generic lambda of header file in implementation file

I have this type in the header MyType.hpp: struct MyType { template void operator(T t) { auto lamdba = [t](auto i){ t.someCall(i); }; someMethod(lamdba); } template void…
Juergen
  • 3,489
  • 6
  • 35
  • 59
0
votes
0 answers

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 const reference of this struct. Is it legal in c++17?…
0
votes
1 answer

How can the Lambda expression be modified to put output in text file?

I have a code, with that I can show the out put on the screen. But, I want to put the output in a text file. Frankly, I read about the Lambda expression, but it is hard for me to understand its function (as I am beginner). #include…
user12034867
0
votes
0 answers

Regarding Lambda Functions in C++

I've been working with C++ for a long time, but I've only recently started to play with lambdas. I have the following example which gives me some trouble figuring it out (why does it behave like this). Keep in mind that this is just an example…
0
votes
1 answer

How to pass a template lambda to a function and use it with different types

I have this code inherited from old C++ time using macros. I'm currently replacing it, and I'm at the point where some constructs need to be factored. Typically, I have this: if(condition) { fun1(fun2(arguments, arg1)); // let's say arg1 is a…
0
votes
1 answer

No type named 'argument_type'

I have this function: void CGuild::AddComment(LPCHARACTER ch, const std::string& str) { if (str.length() > GUILD_COMMENT_MAX_LEN) return; char text[GUILD_COMMENT_MAX_LEN * 2 + 1]; DBManager::instance().EscapeString(text,…
Dev
  • 677
  • 1
  • 8
  • 19