Video & On-Demand

Using C++11 to Speed Up Your Qt 5 Programs -- Marc Mutz

Last month's Qt DeveloperDays Europe videos are now available, including this one showing continued rapid adoption of C++11.

Using C++11 to Speed Up Your Qt 5 Programs (PDF slides)

Marc Mutz

Qt 5 comes with much-improved support for C++11. This talk will teach you techniques that you can use to make your applications use less memory or execute faster when compiled with a C++11 compiler. The focus is on techniques that will not break compatibility with C++98 compilers. After a look at the present state of C++11 support in Qt 5.0, the talk closes with a look at what we can expect in Qt 5.1.

From the summary slide "C++11 @ QT 5.0":

  • constexpr added to many types
  • move semantics added to a few types
  • initializer_list added to most types
  • new few N-ary ctors marked explicit, N >= 2
  • = delete used almost ubiquitously
  • noexcept added in a few central places

Systematic Error Handling in C++ -- Andrei Alexandrescu

Channel 9 has just posted a video of Andrei Alexandrescu’s "Systematic Error Handling in C++11" presented at C++ and Beyond 2012 last summer in Asheville, NC. This is a great 90-minute talk with useful insights and techniques for programming in general and programming in C++11 in particular.

Systematic Error Handling in C++11

Andrei Alexandrescu

Writing code that is resilient upon errors (API failures, exceptions, invalid memory access, and more) has always been a pain point in all languages. This being still largely an unsolved (and actually rather loosely-defined) problem, C++11 makes no claim of having solved it. However, C++11 is a more expressive language, and as always more expressive features can be put to good use toward devising better error-safe idioms and libraries.

This talk is a thorough visit through error resilience and how to achieve it in C++11. After a working definition, we go through a number of approaches and techniques, starting from the simplest and going all the way to file systems, storage with different performance and error profiles (think HDD vs. RAID vs. Flash vs. NAS), and more. As always, scaling up from in-process to inter-process to cross-machine to cross-datacenter entails different notions of correctness and resilience and different ways of achieving such.

To quote a classic, "one more thing"! An old acquaintance -- ScopeGuard -- will be present, with the note that ScopeGuard11 is much better (and much faster) than its former self.

Shevlin Park: A C++ AMP Implementation in Clang/LLVM Using OpenCL -- Dillon Sharlet

At the November 2012 LLVM Developers' Meeting, Dillon Sharlet of Intel gave a presentation on Shevlin Park, a prototype implementation of C++ AMP in Clang/LLVM using OpenCL. In this talk Dillon briefly discusses C++ AMP in comparison to OpenCL, details the implementation and shows the results of performance analysis on the prototype implementation.

Shevlin Park: A C++ AMP implementation in Clang/LLVM using OpenCL (MP4 video) (PDF slides)

Dillon Sharlet - Intel

We describe “Shevlin Park,” a prototype implementation of Microsoft’s C++ AMP built on Clang, LLVM, and OpenCL.

We fully describe Shevlin Park’s implementation including how Clang/LLVM can be augmented to easily accommodate C++ AMP programming constructs, how C++ AMP computation can be expressed as OpenCL compute kernels, and finally how the C++ AMP runtime library can be easily implemented on an OpenCL runtime.

Using several benchmarks, we evaluate Shevlin Park’s performance, Microsoft’s DirectX based C++ AMP, and also conventional OpenCL.

Modules update video available -- Doug Gregor

MP4 video of Doug Gregor's talk on Modules is now available via llvm.org. Combining links here:

Modules (MP4 video) (PDF slides)

Doug Gregor - Apple

The C preprocessor has long been a source of problems for programmers and tools alike.

Programmers must contend with widespread macro pollution and #include-ordering problems due to ill-behaved headers. Developers habitually employ various preprocessor workarounds, such as LONG_MACRO_PREFIXES, #include guards, and the occasional #undef of a library macro to mitigate these problems.

Tools, on the other hand, must cope with the inherent scalability problems associated with parsing the same headers repeatedly, because each different preprocessing context could effect how a header is interpreted – even though the programmer rarely wants it.

Modules seeks to solve this problem by isolating the interface of a particular library and compiling it (once) into an efficient, serialized representation that can be efficiently imported whenever that library is used, improving both the programmer’s experience and the scalability of the compilation process.

 

Exception-Safe Coding in C++ -- Jon Kalb

Jon Kalb from the C++ Now 2012 conference.

Exception-Safe Coding in C++

by Jon Kalb

Are you 100% confident that your code is exception-safe?

Safe usage of exceptions is a non-trivial problem that the industry has struggled with for the better part of two decades. If you have fear, uncertainty, or doubt about exception safety or just want to see the best practices for using exceptions in C++, this session is for you. We'll start with "What is the problem we are trying to solve?" and discuss alternatives, acknowledge the challenges associated with with exception usage, and cover some well-meaning but misguided attempts at safety. I will then present a set of guidelines that are the basis for safe exception usage and solid implementation techniques, including how to transition from an exception-unsafe legacy code base.

When we are finished you will know how to produce code that is easier to write, easier to understand, faster, and 100% robust in the face of exceptions.

This is a two part video series. Links:

Enjoy!

Podcast: Hanselminutes interviews Herb Sutter

A few weeks ago at the Build conference, Scott Hanselman sat down to talk with Herb Sutter about C++ and modern UI/UX. The podcast is now live here:

The Hanselminutes Podcast, Show #346

“Why C++” with Herb Sutter

Topics Scott and Herb discuss include:

  • 2:00 Scott mentions he has used C++ in the past. C++ has changed. We still call it C++, but it’s a very different language now.
  • 5:30 (Why) do we care about performance any more?
  • 10:00 What’s this GPGPU thing? Think of your GPU as your modern 80387.
  • 13:45 C++ is having a resurgence. Where is C++ big?
  • 18:00 Why not just use one language? or, What is C++ good at? Efficient abstraction and portability.
  • 21:45 Programmers have a responsibility to support the business. Avoid the pitfall of speeds & feeds.
  • 24:00 Herb's experience with his iPad, his iPhone, and his Slate 7 with Win8.
  • 28:45 We’re in two election seasons – (a) political and (b) technology (Nexus, iPad Mini, Surface, ...). Everyone is wallpapering the media with ads (some of them attack ads), and vying for customer votes/$$, and seeing who’s going to be the winner.
  • 35:00 Natural user interfaces – we get so easily used to touch that we paw all screen, and Scott’s son gets so used to saying “Xbox pause” that anything that doesn’t respond is “broken.”

 

C++ Questions and Answers -- Herb Sutter

This blog post was suggested by Blair Davidson. The video is from summer 2011, shortly before the C++11 standard was ratified:

Herb Sutter: C++ Questions and Answers

Jun 07, 2011

Herb's [previous] appearance on C9 was a relatively short chat with me about C++0x. You wanted more questions asked and some of you thought I was just too soft on Herb. Well, Herb decided that the best way to get the questions you want asked is, well, to have you ask them. Most of the highest user-rated questions were asked and Herb answers with his usual precision. So, without further ado, it's C++ question and answer time with Herb Sutter, powered by you.

Continue reading...

The Future of C++ -- Herb Sutter

Yesterday, many thousands of you were in the room or live online for Herb Sutter's talk, now available online:

The Future of C++

Herb Sutter
November 2, 2012

From Herb's video announcement summary:

This has been a phenomenal year for C++, since C++11’s publication just 12 months ago. And yesterday was a great day for C++.

Yesterday I had the privilege of announcing much of what Microsoft and the industry have been working on over the past year.

(minor) C++ at Microsoft

On September 12, we shipped VC++ 2012 with the complete C++11 standard library, and adding support for C++11 range-for, enum class, override and final. Less than two months later, yesterday we announced and shipped the November 2012 CTP, a compiler add-in to VC++ 2012 adding C++11 variadic templates, uniform initialization and initializer_lists, delegating constructors, function template default arguments, explicit conversion operators, and raw string literals. Details here, and download here.

Note that this is just the first batch of additional C++11 features. Expect further announcements and deliveries in the first half of 2013.

(major) C++ across the industry

Interest and investment in C++ continues to accelerate across the software world.

  • ISO C++ standardization is accelerating. Major companies are dedicating more people and resources to C++ standardization than they have in years. Over the next 24 months, we plan to ship three Technical Specifications and a new C++ International Standard.
  • C++ now has a home on the web at isocpp.org. Launched yesterday, it both aggregates the best C++ content and hosts new content itself, including Bjarne Stroustrup’s new Tour of C++ and Scott Meyers’ new Universal References article.
  • We now have a Standard C++ Foundation. Announced yesterday, it is already funded by the largest companies in the industry down to startups, financial institutions to universities, book publishers to other consortia, with more members joining weekly. For the first time in C++’s history since AT&T relinquished control of the language, we have an entity – a trade organization – that exists exclusively to promote Standard C++ on all compilers and platforms, and companies are funding it because the world runs on C++, and investing in Standard C++ is good business.

This is an exciting time to be part of our industry, on any OS and using any language. It’s especially an exciting time to be involved with C++ on all compilers and platforms.

Thank you all, whatever platform and language you use, for being part of it.

Links:

Core C++, 5 of N: Explicit and Partial Specialization -- Stephan T. Lavavej

Core C++, 5 of N: Explicit and Partial Specialization -- Stephan T. Lavavej

Stephan T. Lavavej, aka STL, will take us on a journey of discovery within the exciting world of Core C++. We know lots of folks are either coming back to C++, coming to C++, or have never left C++. This lecture series, in n parts, is for all of you! Only STL can make that work (novice, intermediate, and advanced all bundled together and presented in a way only STL can do).

In Part 5, Stephan teaches us about Explicit and Partial Specialization of class and function templates.

From MSDN ->

Class templates can be specialized for specific types or values of the template arguments. Specialization allows template code to be customized for a specific argument type or value. Without specialization, the same code is generated for each type used in a template instantiation. In a specialization, when the specific types are used, the definition for the specialization is used instead of the original template definition. A specialization has the same name as the template of which it is a specialization. However, a template specialization can be different in many ways from the original template. For example, it can have different data members and member functions.

Use specialization to customize a template for a specific type or value. Use partial specialization when the template has more than one template argument and you only need to specialize one of them, or when you want to specialize behavior for an entire set of types, such as all pointer types, reference types, or array types.

// explicit_specialization1.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

// Template class declaration and definition
template <class T> class Formatter
{
   T* m_t;
public:
   Formatter(T* t) : m_t(t) { }
   void print()
   {
      cout << *m_t << endl;
   }
};

// Specialization of template class for type char*
template<> class Formatter<char*>
{
   char** m_t;
public:
   Formatter(char** t) : m_t(t) { }
   void print()
   {
      cout << "Char value: " << **m_t << endl;
   }
};

int main()
{
   int i = 157;
   // Use the generic template with int as the argument.
   Formatter<int>* formatter1 = new Formatter<int>(&i);

   char str[10] = "string1";
   char* str1 = str;
   // Use the specialized template.
   Formatter<char*>* formatter2 = new Formatter<char*>(&str1);

   formatter1->print();
   formatter2->print();
}