my favorite c 10 liner
Download
Skip this Video
Download Presentation
My Favorite C++ 10-Liner

Loading in 2 Seconds...

play fullscreen
1 / 5

My Favorite C++ 10-Liner - PowerPoint PPT Presentation


  • 170 Views
  • Uploaded on

My Favorite C++ 10-Liner. Herb Sutter. How Easy Is C++, Really? 13 +5 LOC Example. # include "cinder/app/ AppBasic.h " #include "cinder/dx/ dx.h " #include <vector> using namespace ci; using namespace ci::app ;

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' My Favorite C++ 10-Liner' - aria


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
how easy is c really 13 5 loc example
How Easy Is C++, Really? 13+5LOC Example
  • #include "cinder/app/AppBasic.h"#include "cinder/dx/dx.h"#include <vector>using namespace ci;using namespace ci::app;
  • class MyApp: public AppBasic {std::vector<Vec2f> points;public: void mouseDrag( MouseEvente ) { 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 )
my favorite c 10 liner1
My Favorite C++ 10-Liner

A complete reference-counted object cache

C++98

  • map operator[] auto-insertion

C++11

  • auto
  • mutex, lock_guard
  • Thread-safe fn statics
  • shared_ptr
  • weak_ptr
  • Thread-safe .lock()
  • shared_ptr<widget> get_widget( int id ) {
  • static map<int, weak_ptr<widget>> cache;staticmutex m;
  • lock_guard<mutex> hold(m);autosp = cache[id].lock();    if (!sp) cache[id] = sp = load_widget(id);    return sp;
  • }

assertion failure: checksum(linecnt)

since i had 3 lines left over
Since I Had 3 Lines Left Over…

Meyers Singleton

C++11

  • Thread-safe fn statics

Bonus: Does destruction!

  • widget& instance() {
  • static widget w;
  • return w;
  • }
ad