using namespace ci; using namespace ci::app ;">
My favorite c 10 liner
This presentation is the property of its rightful owner.
Sponsored Links
1 / 5

My Favorite C++ 10-Liner PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on
  • Presentation posted in: General

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 ;

Download Presentation

My Favorite C++ 10-Liner

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


My favorite c 10 liner

My Favorite C++ 10-Liner

Herb Sutter


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;

  • }


My favorite c 10 liner2

My Favorite C++ 10-Liner


  • Login