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
2
votes
3 answers

why std::integral_constant is necessary in exploding a std::tuple?

#include #include #include #include template auto make_index_dispatcher(std::index_sequence) { return [](auto&& f) { (f(std::integral_constant{}), ...);…
q0987
  • 34,938
  • 69
  • 242
  • 387
2
votes
1 answer

C++ template code generation Error: use of 'some_variable' before deduction of 'auto'

I ran into some issues with this specific code. The problem has most likely something to do with pointer to member of type Harry stored in a tuple, and a vector with Harrytype variable since all other more simple variants do work. The error that I…
2
votes
1 answer

Method template as functor

I have a container class template containing members of several different types. I would like to pass a functor which is called for each of the elements. I can do what I want with the following code: #include template
Philipp
  • 11,549
  • 8
  • 66
  • 126
2
votes
1 answer

Why doesn't raw curly constructor {} return an rvalue?

Lets say you have a variadic class with a std::tuple, that can be move constructed with args + 1 new arg. When constructed using std::apply() and a raw curly brace constructor, that constructor doesn't return an rvalue. Which means the class isn't…
scx
  • 3,221
  • 1
  • 19
  • 37
2
votes
2 answers

MSVC lambda with two auto params of same type

It seems that Visual Studio behaves differently from GCC and Clang given the following code: auto f2 = [](auto x, decltype(x) y) { return x + y; }; f2(1, 2); Clang and GCC will accept this, but MSVC will complain with the message error C3536:…
Pascal T.
  • 3,866
  • 4
  • 33
  • 36
2
votes
3 answers

Wrapper for template callback?

Immediate callback Consider the following example: template void call_me_back(const lambda & callback) { // Very complicated calculation to find the meaning of everything callback(42); } int main() { …
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
2
votes
2 answers

Check a type is a functor including generic lambda

Can I write a trait metafunction to figure out if a type is a functor or not? There are tons of code which can check functor using SFINAE of decltype(&T::operator()), for instance, template struct is_functor { template
slyx
  • 2,063
  • 1
  • 19
  • 28
2
votes
1 answer

Generic lambda, type deduction of actual parameter (auto)

Consider: struct Foo { std::vector data () const { return vec; } const std::vector& c_data () const { return vec; } std::vector vec {}; }; auto lambda1 = [] (const std::vector&) {}; auto lambda2 = []…
Artur Pyszczuk
  • 1,920
  • 1
  • 16
  • 23
1
vote
2 answers

Str object has no attribute 'keys' while using Lambda function in Pandas

I get the errors - 'str' object has no attribute 'keys' while running the lambda codes to explode. ID CODES A {"1407273790":5,"1801032636":20,"1174813554":1,"1215470448":2,"1053754655":4,"1891751228":1} B …
Santoo
  • 355
  • 2
  • 10
1
vote
1 answer

Java: Implement recursive cached from cached Function and cached BiFunction

TLDR: How to implement this function? public static Function cachedRecursive(final BiFunction, R> bifunc) { } I need to somehow extract the second argument from the BiFunction so I can return a proper…
Dominick Navarro
  • 752
  • 6
  • 20
1
vote
1 answer

Mutate return type of a lambda

The full context of this problem is unfortunately too involved to explain, but suffice to say it involves some complicated template metaprogramming and I find myself having to do some funny things. I've tried to boil down an issue I've encountered…
cydonian
  • 1,686
  • 14
  • 22
1
vote
0 answers

Can I change the template argument deduction order for a generic variadic lambda?

Take the following code, which is a simplified example: template void foo(F f) { //bool some = is_variadic_v; // Scenario #1 bool some = true; // Scenario #2 f(int(some), int(some)); } int main() { auto…
Jodocus
  • 7,493
  • 1
  • 29
  • 45
1
vote
1 answer

returning LinkedHashMap from IntStream, Java 8

I have this code. private static Map> alternativeMethod(AudioFormat audioformat, List listChunkDTO, long index, int sizeChunk) { int numBytesPerSample = audioformat.getSampleSizeInBits() / 8; …
joseluisbz
  • 1,491
  • 1
  • 36
  • 58
1
vote
1 answer

How to call std::visit inside a lambda with a visitor that is a function object captured by value

It seems like it is not straightforward to call std::visit within a lambda using a visitor that is a function object captured by value. Capturing by reference works fine though. Why is this the case and is it somehow possible to do this? I do not…
noubius
  • 15
  • 4
1
vote
1 answer

std::visit does not recognise types

I'm stumped that after some code refactoring, the following piece of code does not work anymore as in it jumps to the auto, auto case and ignores the Complex, Complex one. I admittedly don't quite understand what the overload is exactly doing, but…
infinitezero
  • 1,610
  • 3
  • 14
  • 29