4 ms·
.then() is just a method. The "anonymous brackets" is a c++11 lambda function. I don't think chaining it like that is common anywhere, yet.
by ksherlock 14y ago
.then() is just a method. The "anonymous brackets" is a c++11 lambda function. I don't think chaining it like that is common anywhere, yet.
- apaprocki 14y agoThe .then() method appears to be something on concurrency::task, which is part of the Microsoft's Parallel Pattern Library. This article says: "we've started a new project called Casablanca to build a modern C++ library for cloud-based client-server communication, in which all concurrent operations are exposed as PPL tasks." http://www.drdobbs.com/parallel/improving-futures-and-callbacks-in-c-to/240004255?pgno=2 http://www.drdobbs.com/parallel/improving-futures-and-callba... Link to Microsoft's C++ committee proposal (N3327): http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3327.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n332...
- HNLogInShit 14y agoUgh. It's "client/server", not "client-server".
- twoodfin 14y agoThat looks like Microsoft's new "async everywhere" approach to API design. It's probably a pretty good idea in concept, but I hope they don't expect C++ developers to actually write those awful nested lambda .then() blocks for what are conceptually sequential actions.
- marshray 14y agoI expect you can define named functions for your "conceptually sequential actions" if you prefer.
- twoodfin 14y agoSure, but is that much better? It reminds me of having to create named struct classes to simulate closures prior to C++11 lambdas. The language syntax just doesn't support that style of programming.
- marshray 14y agoSo how many languages actually do support this style directly? The C# async keyword looks pretty clean, just give C++ a decade or so to catch up.
- MichaelGG 14y agoIs there a better approach available in C++? In other languages you'd use monads or other special compiler forms that can rewrite sequential looking code into the horrible multi-nested callback/error handling code it needs to be.
- ajasmin 14y agoBoost Coroutines perhaps? http://www.boost.org/doc/libs/1_53_0/libs/coroutine/doc/html/index.html http://www.boost.org/doc/libs/1_53_0/libs/coroutine/doc/html...
- Figs 14y agoI've used that style of programming in some of my hobby projects (mixed with other obvious sequencing operations like wait_until(predicate) and delay(time)) for doing timeline scripting. In my experience, it tended to become a mess when I needed things more complex than linear action sequences (e.g. conditionals, loops, etc. are better suited to a real interpreter). As far as common uses of chaining for sequencing in C++, the only common use that comes to mind is iostreams operator <<, but that predates lambdas.