Tag Archives: Stephan Lavavej

Going Native 2013 – Don’t Help the Compiler, Stephan Lavavej

This presentation from Stephan Lavavej could have been entitled “Compiler Knows Best” – he rockets through numerous examples where the advice is to write less code and let the compiler do the right thing.

Here’s a slide of one of the key messages:

20140207-183930.jpg

Other highlights for me:

  • decltype(auto) coming in C++14 looks very cool (eliminates duplicate code when using auto with decltype for late-specified return values)
  • Don’t call std::make_pair( x, y ) – the T, U are inferred by template argument deduction, so should always be left out (unless you want to force a type conversion when T != typeof(x) e.g. short -> long
  • Use nullptr because it is convertable to all pointer types, but 0 and NULL are always type int

I love the new features of C++11 and couldn’t have written some of the cool libraries I’m working on without them. But – presentations like this make me concerned for the complexity of the language and the steep learning curve that even experienced C++ hires will have to climb.

Leave a comment

Filed under C++, Programming, Video

Stephan Lavavej’s make_unique proposal

Stephan Lavavej has submitted a proposal to the C++ Standards committee for make_unique (the std::unique_ptr equivalent to std::make_shared for std::shared_ptr).

make_unique’s presence in the Standard Library will have several wonderful consequences. It will be possible to teach users “never say new/delete /new[]/delete[]” without disclaimers. Additionally, make_unique shares two advantages with make_shared (excluding the third advantage, increased efficiency). First, unique_ptr<LongTypeName> up(new LongTypeName(args)) must mention LongTypeName twice, while auto up = make_unique<LongTypeName>(args) mentions it once. Second, make_unique prevents the unspecified-evaluation-order leak triggered by expressions like foo(unique_ptr<X>(new X), unique_ptr<Y>(new Y)). (Following the advice “never say new” is simpler than “never say new, unless you immediately give it to a named unique_ptr”.)

It’s a really useful utility as demonstrated in this video.

Leave a comment

Filed under C++

Stephan Lavavej Video – VS2012 C++ November CTP

Introductory video on the Visual Studio 2012 C++ Compiler November CTP (download the CTP here):

A special episode in which Stephan takes a look at the latest C++11 features that were just added to the Visual C++ compiler:

Variadic templates
Raw string literals
Explicit conversion operators
Default template arguments for function templates
Delegating constructors
Uniform initialization

Click to watch the video

Leave a comment

Filed under C++, Video