On Sun, May 23, 2010 at 08:44:42PM +0100, Chris Cannam wrote: > On Sun, May 23, 2010 at 9:41 AM, torbenh <[email protected]> wrote: > > but i find the equivalen c++ easier to read. > > assuming we have a proper modern c++ osc lib: > > > > boost::unique_future<OscMsg> > > osc_recv (OscPeer peer, std::string path) > > { > > boost::shared_ptr< boost::promise<OscMsg> > spromise( new > > boost::promise<OscMsg> ) > > peer.add_handler( path, [=]( OscMsg msg ) > > { > > [...] > > Is this C++0xthingy?
the [=] is the c++0x lambda/closure. [=] copies all referenced variables into the closure. i didnt really use it yet. and i am not sure how to indent it properly. but its basically an inplace function definition. [=] means COPY all referenced variables. [&] would mean reference. since the closure would be executed outside of the stack frame of osc_recv the spromise needs to be copied. yes. the other stuff is from boost::threads but will be in c++0x std:: namesapce. however gcc-4.5 doesnt have the threading in its std lib yet. although i looked and the future is already there. the availability of promisses is the major argument why people are pushing clojure. and writing equivalent code to using promises and futures without using them would be a bit pointless. they are in boost, and they will/are be in the std:: > > I have to say this combination of Boost plus Weird Stuff From The > Future is no more readable to me (as a long-time C++ programmer) than > the Clojure example. It looks neat, but I'm pretty sure it's > accessible to you only because it's what you've spent the time with > recently. well... the lambdas are new to me too. never used them yet. note that this isnt stuff from the future. ok. it might change a bit. and probably gcc-4.5 shouldnt really be required until its 4.5.2 > > I worry about that all the time with my own code -- the more care I > take to use the language well, the less likely anyone else is to be > able to work with it. well... for me, saying c++, is saying boost. boost and modern c++ is what makes c++ better than java. java is a pretty great language nowadays (with generics and annotators and stuff). my big problem with java is that its stdlib is really a big mess. > > > Chris -- torben Hohn _______________________________________________ Linux-audio-dev mailing list [email protected] http://lists.linuxaudio.org/listinfo/linux-audio-dev
