C++11/14 Idioms I Use Every Day—Paul Cechner

Start your Monday the right way by sending this to three of your friends who are new to (modern) C++:

C++11/14 Idioms I Use Every Day

by Paul Cechner

From the article:

Most attention on the new C++ has focused on the changes that provide functionality and performance that was previously not possible, both library enhancements (chrono, regex, smart pointers, and stuff to help with lambdas for example) and core language enhancements (perfect forwarding, variadic templates, the new memory model and threading capabilities, initialiser lists and the like). This functionality will impact us all in helping to write more correct code and efficient libraries, but often will only be relevant in certain parts of our code.

But the first thing that struck me when I started using C++11 was the smaller features that I could take advantage of every time I put my fingers to the keyboard. These are the things that make code more concise and simple and allow me to present my intentions more clearly. ...

Quick Q: Does make_shared avoid an extra allocation for the reference counts?—StackOverflow

A: Yes, make_shared is your friend!

Recently on SO:

What happens when using make_shared

I'm interested if these two lines of code are the same:

shared_ptr<int> sp(new int(1)); // double allocation?
shared_ptr<int> sp(make_shared<int>(1)); // just one allocation?

If this is true could someone please explain why is it only one allocation in the second line?

HTTP and HTTPS in Qt

How to handle HTTP and HTTPs requests in Qt

HTTP and HTTPs in Qt

by Jens Weller

From the article:

Last week I started to work on an old project again: My own feed reader. I found the code 2 weeks a go on an old USB Stick, and decided to refactor it into a useful state. This involved dealing with HTTP via QNetworkAccessManager.

A Clang edition of the C++11/14 Rocks book is now available

Korban's C++11/14 feature overview book now has a Clang edition, in addition to VS2013 and GCC:

Clang Edition of the C++11/14 Rocks Book

by Alex Korban

From the announcement:

Do you use Clang to compile C++? Would you like to know all about the C++11 and C++14 language features it supports?

You can read about them in the new edition of my C++11/14 Rocks book tailored to Clang.


For those who have the GCC edition of the book: you’ll already be familiar with all the C++11 content as GCC also has full C++11 support. However, the Clang edition has full C++14 coverage instead of an overview.

Non-Static Data Member Initializers—741MHz

In case you missed it:

Non-Static Data Member Initializers

by 741MHz

From the article:

...  This problem is addressed in C++11 by allowing non-static data members to be initialized along with a declaration. For example, the following syntax is allowed:

struct foo {
    double x = 1.23;
    int y = 1;
    int z = 2;

This also works well with multiple constructors. The class described above could now be simplified and made easier to maintain further down the road: ...


Inheriting Constructors in C++11—741MHz

Following up on Monday's linked article:

Inheriting Constructors in C++11

by 741MHz

From the article:

Delegating Constructors [... are] extremely useful in boosting efficiency, [but] it does not solve the problem when programmer wants to create a derived class that has exactly the same set of constructor as its base class or classes. In which case programmers are forced to tediously duplicate constructors of the base class...

C++11 solves this problem by introducing constructor inheritance. In a derived class, programmers can write a single using T::T; statement that makes a derived class automatically inherit constructors of a base class. For example: ...

Delegating Constructors in C++11—741MHz

In case you missed it on 741MHz:

Delegating Constructors in C++11

by 741MHz

From the article:

C++ has caught up with other popular object-oriented languages such as Scala, Java, C# and others when it comes to constructor delegation, a feature that is now supported as per 2011 core language specification of ISO C++. This solves a common problem with repetitive coding, which is tedious and fragile, that C++ programmers had to do in order to provide multiple class constructors.


C++11 allows that a constructor of a class type “A” may have an initializer list that invokes another constructor of the same type. Therefore, programmers can get rid of undesirable common initialization function and duplicate all at once by writing the code like this: ...

Making the Most of C++11/14—Sasha Goldshtein

New on Lanyrd:

Making the Most of C++11/14 (slides)

by Sasha Goldshtein

The C++11 standard is already behind us, and C++14 is just around the corner. With a huge variety of language features such as lambdas, rvalue references, auto and decltype, and variadic templates, it's easy to get lost in C++. In fact, it often seems like a completely new and foreign language. In this workshop we will look at the most important language features that improve system performance and developer productivity, with a glimpse towards what C++14 will bring. We will make the most of Visual C++ 2013 and see how to convert and refactor code to use modern C++ idioms.

C++11 Final Override—741MHz

A good article posted last year and making the rounds again this week:

C++11 Final Override

by 741MHz

From the article:

C++11 introduces two important keywords in relation to polymorphism and inheritance — the override and final. Using those keywords should become a habit of any C++ developer. It is worth using every time except when writing a base class. This will make the code clear, maintainable, and potentially save hours that would have been otherwise wasted chasing an error in debugger.