Articles & Books

A tale of noexcept swap for user-defined classes in C++11 -- Sumant Tambe

From the C++ Truths blog, with a creative use of std::tuple:

A tale of noexcept swap for user-defined classes in C++11

by Sumant Tambe

From the article:

I like my strong exception safety in my little copy-assignment operator so I don’t want my swap to throw but I don’t want my program to std::terminate() if an exception is really thrown. With all that in mind, I would rewrite the swap as follows...

This is not unlike what’s proposed by others but there’s more. The static assert looks awful and looks redundant. There is already a standard library utility that does the same thing: std::tuple. As mentioned before, std::tuple’s swap throws if any member swap throws. We use it here to make our job a lot easier...

C++ User Group Meetings in May

Again, a list of user group meetings for this month. In total its going to be 16 user groups meeting this month:

C++ User Group Meetings in May 2014

by Jens Weller

From the Article:

The Meetings

    8th May C++ UG Aachen - SIMD Programmierung
    8th May C++ UG Belgium
        Parallelism in the C++ Standard, what to expect from C++17
        Asynchronous Programming with futures and await
    8th May C++ UG Dresden - C++ Memory Model
    8th May C++ UG New York - Whats next for C++
    13th May C++ UG Philadelphia - Profiling and Perfomance
    14th May C++ UG San Francisco/Bay area
    15th May C++ UG Malmö/Sweden - Battle of the build systems
    19th May C++ UG Denver - CppNow, Eclipse Configuration, Qt Creator and more...
    20th May C++ UG Berlin - C++ in the demo scene
    21st May C++ UG Düsseldorf - Expression Templates
    21st May C++ UG Hamburg
    21st May C++ UG Seattle/Northwest - Agile Architecture
    23rd May C++ UG Paris
        Introspection et reflection en C++
        Le SIMD en pratique avec boost SIMD
        Clang & C++
    27th May C++ UG Chicago
    28th May C++ UG Heidelberg
    28th May C++ UG San Francisco/Bayarea - C++Now tripreport

Fast Polymorphic Collections -- Joaquín M López Muñoz

munuz-poly.PNGOn the theme of "contiguous enables fast":

Fast Polymorphic Collections

by Joaquín M López Muñoz

From the article:

poly_collection behaves excellently and is virtually not affected by the size of the container. For n < 105, the differences in performance between poly_collection and a std::vector of std::unique_ptrs are due to worse virtual call branch prediction in the latter case; when n > 105, massive cache misses are added to the first degrading factor.

A C error handling style that plays nice with C++ exceptions

If you've ever wondered why someone might throw an exception from a destructor, this article provides a legitimate example:

A C Error Handling Style that Plays Nice with C++ Exceptions

by Stefanus Du Toit

From the article:

By choosing a particular convention for a C API's error handling, we were able to very conveniently translate errors from the C API to C++ exceptions. ... Every experienced C++ programmer I know has opinions on how errors should be handled. I've found this style to be quite useful when layering C++ on top of C, and I think there's some beauty in the interplay between C and C++ here.

 

Quick Q: If I use shared_ptrs to own objects, must I use weak_ptrs to observe them? -- StackOverflow

Quick A: No. Remember that weak_ptr and * are both valid non-owning pointers. Use * when you know the pointed-at object will outlive this pointer. Use weak_ptr when you don't know whether the pointed-at object will outlive this pointer, and the pointed-at object is owned by shared_ptrs.

For more good information, see the top answer to this question yesterday on SO:

Smart pointers + cycles + “->”

Sometimes I'm really sure that I want to have circular dependence of pointers, and every object on cycle should be able to use his pointer (so it can't be weak_ptr).

My question is: Does this mean that I have bad design?

What if I want to implement graph? Can I use smart pointers? In graphs there are cycles, but with weak_ptr I can't use "->". What can I do?

I read some articles, reference and topics on StackOverflow, but it looks like I still don't get smart pointers. Really, why doesn't exists some variant of weak_ptr with "->"?

Qt & JSON

Recently I could play around with Qt5 JSON API:

Qt & JSON

by Jens Weller

From the Article:

With Qt5 there is a new API for reading and writing JSON files in Qt. In the last days I had the chance to play around with this API, as I implemented importing and exporting different data sets from and to JSON.

Quick Q: Are class member initializers evaluated at compile time? -- StackOverflow

Quick A: Maybe.

Recently on SO:

Does in class member initialization takes place at compile time or run-time?

In C++11 a new feature was introduced where the programmer can initialize class member variables inside class's definition, see code below:

struct foo
{
  int size = 3;
  int id   = 1;
  int type = 2;
  unsigned char data[3] = {'1', '2', '3'};
};

Is this initialization takes place during compile time or this feature is just syntactic sugar and member variables are initialized in the default constructor?

Nugget: Context-sensitive keywords -- Tony DaSilva

Recently on Bulldozer00:

Context Sensitive Keywords

by Tony DaSilva

From the article:

With the seriousness of keyword introduction in mind, one might wonder why the override and final keywords were added to C++11. Surely, they’re so common that millions of lines of C/C++ legacy code will get broken. D’oh!

But wait! To severely limit code-breakage, the override and final keywords are defined to be context sensitive...

Range Comprehensions -- Eric Niebler

Do you "comprehend" ranges? From a key participant in some of the latest discussion about ranges for C++:

Range Comprehensions

by Eric Niebler

From the article:

I’ve been busy since I last wrote about ranges. I have a lot of news to share, but in this post, I’m going to narrowly focus on a recent development that has me very excited. It’s a new feature that I’m calling range comprehensions, and they promise to greatly simplify the business of creating custom ranges...