

C++0x (upcoming C++ standard, includes lambda functions) - jacquesm
http://en.wikipedia.org/wiki/C%2B%2B0x

======
chc
So the lambda functions are implemented in a way that only really works with
templates and you have to explicitly pass scope? I don't really write C++
"natively," but this seems awkward to me, particularly vis-a-vis Apple's
implementation of blocks in C. Does it look better to anyone who has a better
handle on the feel of idiomatic C++?

~~~
bff
I've been using them for a while now (gcc has support) and they're not
awkward. The ability to specify scope is actually rather nice and most of the
time you'll either leave the scope empty with [] or pass everything in by
value [=] or reference [&]. The return type of the lambda function is also
usually detectable by the compiler so you only need to specify it rarely.

~~~
okmjuhb
To be more specific: the return type of the lambda can be omitted for a lambda
whose body is just "return {expression}". The compiler could, if it wanted,
always deduce the return type (since implementing type inference would be
easy). The fact that it doesn't isn't to make it easy for compilers; it was a
design decision of the language: having unspecified return types for
complicated pieces of code hurts readability and maintainability.

~~~
bff
Return types can't always be deduced since they can be ambiguous - imagine an
if statement where one branch returns a float and the other returns a double.
The desired return type could really be any numeric value since the types can
be converted so the return type does need to be specified. Since C++ has
overloaded functions the compiler can't just look at the function that the
result is being passed into to determine the type either.

~~~
okmjuhb
The solution would be then to do autoconversions as appropriate or return an
error.

The compiler already deals with this issue with the ?: operator. It's a
readability and maintenance problem there, too. It'd be easy to do; the
language designers chose not to.

------
faragon
C++ it's getting ridiculous, just like strange mix becoming a Tower of Babel.

P.S. I've working with C++ for more than 10 years.

~~~
bff
I thought the same thing when I starting working with the new standard, but
I've really grown to enjoy a lot of the new features, specifically the new
pointer types, rvalue references, initializer lists, variadic templates, and
better support for functional programming via binds and lambdas. C++0x really
does fix a lot of things that were broken on awkward previously, while also
expanding support for memory and speed constrained systems via things like
std::array. For me, this stuff breaths new life into the language.

~~~
faragon
<http://en.wikipedia.org/wiki/The_Emperor%27s_New_Clothes>

------
exit
does it eliminate header files D: ?

~~~
jonhohle
I may be in the minority, but I like header files. Interface =>
Implementation, enforced at the file level. Add Obj-C's #import macro and they
even look reasonable!

~~~
ben_straub
Well, you either have to publish your member variables and their names to the
world, or use PIMPL, which is (I think) a bit of a hack. Having partial
classes (a la C#) would be nice for this.

------
lanstein
errr haven't we missed the boat on 0x? My calendar says 2010.

~~~
jacquesm
<http://en.wikipedia.org/wiki/C1X> is the new 'C' draft standard, I think that
the C++ guys figured they'd be ready a bit earlier than this. They might name
it C++09 to save face.

~~~
lanstein
After edit, your comment makes more sense. I have no doubt that they figured
they'd be ready earlier than this ;)

------
inodeman
Are these lambdas going to be same as blocks on iOS?

~~~
ben_straub
Not at all. Behind the compiler curtain, they're the same as functors
(<http://www.newty.de/fpt/functor.html>)

