POV-Ray : Newsgroups : povray.off-topic : Standard libraries : Re: Standard libraries Server Time
6 Sep 2024 13:17:50 EDT (-0400)
  Re: Standard libraries  
From: Nicolas Alvarez
Date: 6 Mar 2009 21:30:12
Message: <49b1dc33@news.povray.org>
Darren New wrote:
> So it's not really a closure, but a downward funarg. That's exactly the
> sort
> of thing I was talking about.  You can't return a lambda, I take it?
> 
> What's the type of
>     [&](int x) { total += x; }
> 
> What kind of variable can I assign that to?

"Lambda functions are function objects of a implementation-dependent type;
this type's name is only available to the compiler. If the user wishes to
take a lambda function as a parameter, the type must be a template type, or
it must create a std::function to capture the lambda value. The use of the
auto keyword can locally store the lambda function"

The 'auto' keyword is what Warp mentioned. I guess you can also use
std::function to safely return a lambda.

"However, if the lambda function captures all of its closure variables by
reference, or if it has no closure variables, then its type shall be
publicly derived from std::reference_closure<R(P)>, where R(P) is the
function signature with return type. This is expected to be a more
efficient representation for lambda functions than capturing them in a
std::function."

All this is from Wikipedia article "C++0x". Next time please do some minimal
research before claiming C++ sucks :)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.