Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's rather harder to count the number of times there were idioms you could have used but didn't because using them in C++ wouldn't have been practical or efficient. I'm thinking in particular of closures which captured state, and functional/monadic style chained method calls each building on the previous function's return value (think: something like .NET LINQ).


It sounds like you're referring to C++98 while the article specifically talks about C++0x. C++0x adds closures to the mix so it's now very possible to implement something similar to .NET LINQ in C++.


No, I'm not; I explicitly mentioned closures which capture state precisely because that's where C++0x gets thorny. You can capture by copying or by reference; what you don't get is wholesale movement of the variable into a heap-allocated location, the way variable capture works in almost every other language supporting free mutation of variables.

I wrote about it in an earlier thread: http://news.ycombinator.com/item?id=2617990


My bad, I wasn't familiar with the term. I'm still not convinced this is a limitation though. If you want to modify an object, passing by reference usually makes perfect sense. For those occasion when this is not the case, you probably already have a smart pointer in your hand, capture it by copy. A counter example would be great.

BTW the behavior you describe has been achieved in the C language family with Apple's C block extension, not that it's relevant since it's in no way standard (aside from Objective-C++)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: