Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
1 answer
120 views

In GCC, inside a lambda, I can get constexpr variable from a non-constexpr template lambda, but not in Visual C++

This code compiles fine in gcc, but fail in Visual C++. MCVE = https://godbolt.org/z/K7d5PEs65 int main(){ int localVariable=0; //some local variable auto lamb=[&]<int s>() { ...
cppBeginner's user avatar
  • 1,116
0 votes
1 answer
115 views

What is the type of a templated lambda?

The following code tries to create a templated lambda and pass it to a function that calls it. However compilation fails because the type of lambda argument is wrong. #include <functional> void ...
Montaner's user avatar
  • 534
0 votes
1 answer
52 views

Count the number of arguments in generic lambda

I want to create a function that counts the number of arguments in generic lambda functions. SO user "yuri kilochek" has a great solution Count the number of arguments in a lambda but it ...
user2961927's user avatar
  • 1,654
4 votes
0 answers
160 views

Using a function's argument to produce the type of another function's argument

Since C++20 abbreviated function templates are available for use with placeholder types in parameter list. And one can declare abbreviated function template g with two arguments of same reference type ...
Fedor's user avatar
  • 19.4k
0 votes
2 answers
74 views

Why code below doesn't compile and what can we do to make it compile in the end?

My code: #include <functional> #include <iostream> template <typename T> void call_with(std::function<void(T)> f, T val) { f(val); } int main() { auto print = [](int ...
enderline13's user avatar
3 votes
1 answer
93 views

Dependent name error in discarded if-constexpr instantiation of function template or generic lambda

From my understanding, dependent name lookup doesn't take place until template instantiation, and template invocations in a discarded if-constexpr statement are not instantiated. As such, I would ...
Ramon's user avatar
  • 1,269
0 votes
0 answers
62 views

How to cast forwarded arguments to std::invoke conditionally (if it's a certain class) which came from std::forward'ed template (SFINAE?)?

I have created a class member invocation function, which does a delayed call, like: func = NotifyAll( &get_file_listener, &GetFileListener::OnGetFileSuccess, container.c_str(), name....
Gizmo's user avatar
  • 2,190
3 votes
1 answer
72 views

Confusion about type deduction in variadic templates

I have a class with multiple constructors, one being variadic and one taking an additional callable before the variadic arguments. However, the objects I create result in overload resolutions I dont ...
Philipp317's user avatar
1 vote
2 answers
175 views

Is it okay to use lambda as a default non-type template argument to generate unique types?

template <auto = [](){}> struct A; using unique_1 = A<>; using unique_2 = A<>; Is it safe to generate unique types like that or that's some sort of ill-formed behaviour?
cppbest's user avatar
  • 219
-2 votes
1 answer
76 views

Why can't I use default template parameters while providing a lambda as an argument? [duplicate]

I have a templated function that takes an std::function argument. #include <iostream> #include <functional> template<typename T1, typename T2> void foo(T1& t, std::function<T2(...
H.v.M.'s user avatar
  • 1,599
1 vote
3 answers
182 views

How to write typed wrapper for a thread pool?

I have a simple thread pool. It takes tasks and distributes them among threads using round-robin. The task looks like this using TaskFn = void (*)(void*); struct Task { TaskFn fn; void* args; ...
VadimP22's user avatar
  • 345
0 votes
1 answer
134 views

deducing general lambdas argument type

I wish to pass void and single argumented direct lambdas to operator call class My { public: template<typename Callable> operator >> (Callable &&callback){ callback(); return *this;...
Vitaly Protasov's user avatar
1 vote
1 answer
96 views

SFINAE error in a trait to find the return type of any callable

I am playing around with SFINAE and trying, as an exercise, to get information about "function-like" objects (functions, function pointers, lambdas, and anything overloading the parenthesis ...
sunmat's user avatar
  • 7,138
1 vote
1 answer
93 views

Inlining lambda calls to template functions

I wish to have a template method, which takes in data and processes it with a lambda function, whatever way the method itself wants to do that. However, I want the lambda function to get inlined so ...
user19179144's user avatar
2 votes
1 answer
95 views

Why I can use a template function as parameter to std::sort but not a template lambda (with member function ptr as template parameter) [duplicate]

Sorry for the long title, as I stated this works: #include <algorithm> #include <iostream> #include <vector> struct S { int a{}, b{}; }; std::ostream &operator<<(std::...
PaperBirdMaster's user avatar

15 30 50 per page
1
2 3 4 5
41