30,326 questions
12
votes
1
answer
872
views
Mirroring C++ Lambda Captures into a POD struct via C++26 Reflection (P2996)
I am working on using C++26 reflection (P2996) to reflect the capture list of a stateful lambda into a nameable POD struct. My goal is to "abuse" the fact that lambdas are typically ...
Best practices
0
votes
4
replies
77
views
Working around spaghetti lambdas and builder in Spring Security v6
I am working to adapt Spring Security v6 in my application and one of the GitHub projects I am using as a model has the following filterChain implementation in its @EnableWebSecurity Configuration ...
-2
votes
1
answer
101
views
How can Mixins be used to inject into a lambda statement [closed]
I am making a Minecraft mod and need to add a Mixin targeting a method invocation inside a lambda body.
I have the following target class:
public class Foo {
public static void bar() {
...
4
votes
2
answers
164
views
Accessing constant variables from a lambda in Visual Studio 2026
I have a program that I would like to build in Visual Studio 2026, but struggle with the errors appearing.
One simplified piece of code is as follows:
void f(const void*) {}
int main() {
...
-2
votes
2
answers
153
views
Why does this function receive 2 positional variables when it is only given one? [closed]
In a recent script I wrote I use the keyboard module for hotkeys but I decided to store all arguments in an array where I would use a loop to call them all. When I attempted to use any hotkey I ...
2
votes
1
answer
136
views
C# expression tree, property convert string to int/long
I have an IQueryable expression:
... Where(x => Convert.ToInt64(x.string_param) > Convert.ToInt64(string_const)) ...
How to build this throught expression tree? Kind of:
var left = ...?
var ...
0
votes
0
answers
118
views
When using lambda expressions with bulk update APIs for EF Core, is the lambda expression evaluated in-memory, or on the DB-side?
I am using the Bulk Update APIs, part of EF Core like the ExecuteUpdateAsync() functions, to perform updates, and I am passing in a lambda for my valueExpression. I am wondering if the evaluation of ...
10
votes
1
answer
586
views
Why does a class inherited from lambda type lack conversion to function pointer in Visual C++?
If a lambda is capture-less, its closure type has conversion operator to function pointer. For example,
auto l = []{};
using F = decltype(+l); //pointer to function type
constexpr F p = l;
And if a ...
6
votes
1
answer
163
views
MSVC accepts lambda with deleted parameterized ctor while GCC and Clang rejects
I wrote the following program that is accepted by MSVC, but is rejected by both GCC and CLANG. What is the standard compliant behavior?
Live Demo
struct C
{
C(int) = delete;
C(){};
};
decltype([b ...
18
votes
1
answer
1k
views
Evaluation order of lambda capture initializers
Consider the following program:
#include <iostream>
int f(int i) {
std::cout << i;
return i;
}
int main() {
[a=f(1), b=f(2)]{}();
}
It prints 12 (with all major c++ ...
5
votes
1
answer
168
views
Lambda with deducing this parameter of unrelated type [duplicate]
A colleague of mine showed me a program with explicit object parameter in a lambda function. The program is accepted by two compilers, but produces a strange result:
struct A {
int a = 2;
...
2
votes
1
answer
140
views
Is there a difference between 'eval' and sourcing a temporary file?
These two examples accomplish the same thing:
# using eval
var=hello
eval "some_func() { echo $var; }"
some_func # "hello"
# using source
var=hello
source <(echo "...
3
votes
1
answer
175
views
Accessing a lambda's parameter leads to "Assignment type mismatch: actual type is 'Unit', but 'String' was expected"
I'm trying to pass a click handler to a child function that sends a string back to the parent and updates a mutable value based on the string. I'm getting an error on the function:
Assignment type ...
0
votes
1
answer
77
views
Array FILTER/TRANSFORM lambda using index
Snowflake supports higher order functions like FILTER or TRANSFORM.
A lambda expression that defines the filter condition on each array element.
The lambda expression must have only one argument ...
4
votes
3
answers
382
views
Passing a local reference to a closure
Consider the code below:
for (T &t : some_vector_) {
futures.push_back(thread_pool.submit([&t] { t.do_something(); }));
}
On some iteration i, t is initialized to a reference to a vector ...