cplusplus:goingnative2013
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | cplusplus:goingnative2013 [2013/09/09 16:19] – created dblume | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Going Native 2013 ====== | ||
+ | Herb Sutter had a couple of favorite C++ few-liners. Watch the video here: [[http:// | ||
+ | |||
+ | A complete reference-counted object cache. | ||
+ | |||
+ | From C++98 it uses map operator[]' | ||
+ | |||
+ | From C++11 it uses: | ||
+ | * auto | ||
+ | * mutex, lock_guard | ||
+ | * Thread-safe fn statics | ||
+ | * shared_ptr and weak_ptr | ||
+ | * Thread-safe.lock() | ||
+ | |||
+ | <file cpp widget_cache.cpp> | ||
+ | shared_ptr< | ||
+ | static map< int, weak_ptr< | ||
+ | static mutex m; | ||
+ | |||
+ | lock_guard< | ||
+ | auto sp = cache[id].lock(); | ||
+ | if( !sp ) | ||
+ | cache[id] = sp = load_widget(id); | ||
+ | return sp; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This one uses the **[[http:// | ||
+ | |||
+ | <file cpp gui_app.cpp> | ||
+ | #include " | ||
+ | #include " | ||
+ | #include < | ||
+ | using namespace ci; | ||
+ | using namespace ci::app; | ||
+ | |||
+ | class MyApp: | ||
+ | std:: | ||
+ | public: | ||
+ | void mouseDrag( MouseEvent e ) { | ||
+ | points.push_back( e.getPos() ); | ||
+ | } | ||
+ | | ||
+ | void draw() { | ||
+ | dx::clear( Color( 0.1f, 0.1f, 0.15f ) ); | ||
+ | dx::color( 1.0f, 0.5f, 0.25f ); | ||
+ | dx::begin( GL_LINE_STRIP ); | ||
+ | for( auto& e: points ) | ||
+ | dx::vertex( e ); | ||
+ | dx::end(); | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | CINDER_APP_BASIC( MyApp, RendererDx ) | ||
+ | </ |
cplusplus/goingnative2013.txt · Last modified: 2023/04/12 20:44 by 127.0.0.1