generic-lambda

c++ lambdas how to capture variadic parameter pack from the upper scope

别来无恙 提交于 2019-11-28 19:20:10
问题 I study the generic lambdas, and slightly modified the example, so my lambda should capture the upper lambda's variadic parameter pack. So basically what is given to upper lambda as (auto&&...) - should be somehow captured in [=] block. (The perfect forwarding is another question, I'm curious is it possible here at all?) #include <iostream> #include<type_traits> #include<utility> // base case void doPrint(std::ostream& out) {} template <typename T, typename... Args> void doPrint(std::ostream&

find out the type of auto

我怕爱的太早我们不能终老 提交于 2019-11-28 00:36:07
I am playing with generic lambda in C++1y and I often confused by don't know what is the type of auto variable/parameter. Is any good way to find it out? Currently I am using typeid(decltype(arg)).name()) but it is not very useful. @encode gives a slightly better result but still hard to decipher it example: auto f = [](auto && a, auto b) { std::cout << std::endl; std::cout << typeid(decltype(a)).name() << std::endl << @encode(decltype(a)) << std::endl; std::cout << typeid(decltype(b)).name() << std::endl << @encode(decltype(b)) << std::endl; }; int i = 1; f(i, i); f(1, 1); f(std::make_unique

Arity of a generic lambda

我的梦境 提交于 2019-11-27 09:28:31
It is possible to deduce arity of a non-generic lambda by accessing its operator() . template <typename F> struct fInfo : fInfo<decltype(&F::operator())> { }; template <typename F, typename Ret, typename... Args> struct fInfo<Ret(F::*)(Args...)const> { static const int arity = sizeof...(Args); }; This is nice and dandy for something like [](int x){ return x; } as the operator() is not templated. However, generic lambdas do template the operator() and it is only possible to access a concrete instantiation of the template - which is slightly problematic because I can't manually provide template

Arity of a generic lambda

◇◆丶佛笑我妖孽 提交于 2019-11-26 22:18:30
问题 It is possible to deduce arity of a non-generic lambda by accessing its operator() . template <typename F> struct fInfo : fInfo<decltype(&F::operator())> { }; template <typename F, typename Ret, typename... Args> struct fInfo<Ret(F::*)(Args...)const> { static const int arity = sizeof...(Args); }; This is nice and dandy for something like [](int x){ return x; } as the operator() is not templated. However, generic lambdas do template the operator() and it is only possible to access a concrete

find out the type of auto

╄→гoц情女王★ 提交于 2019-11-26 21:45:44
问题 I am playing with generic lambda in C++1y and I often confused by don't know what is the type of auto variable/parameter. Is any good way to find it out? Currently I am using typeid(decltype(arg)).name()) but it is not very useful. @encode gives a slightly better result but still hard to decipher it example: auto f = [](auto && a, auto b) { std::cout << std::endl; std::cout << typeid(decltype(a)).name() << std::endl << @encode(decltype(a)) << std::endl; std::cout << typeid(decltype(b)).name()

Is there a name for this tuple-creation idiom?

混江龙づ霸主 提交于 2019-11-26 17:29:35
问题 On the Boost mailinglist, the following clever trick to create a tuple-like entity was recently posted by @LouisDionne: #include <iostream> auto list = [](auto ...xs) { return [=](auto access) { return access(xs...); }; }; auto length = [](auto xs) { return xs([](auto ...z) { return sizeof...(z); }); }; int main() { std::cout << length(list(1, '2', "3")); // 3 } Live Example. The cleverness is that list is a lambda taking a variadic parameter-list as input, and returning a lambda as an output