May 2014

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...

Talks for Meeting C++ 2014 are online

I released most of the talks for this years Meeting C++ conference:

Meeting C++ 2014 - Talks

I have yet only published the talks where I could reach the speakers. So some more to come. The popular Track in the mainhall is also alreay known:

  • Monads in chains
  • Expression Templates Revisited: Separating Facts from Urban Legends
  • Pruning Error Messages From C++ Template Code
  • Sqlpp11, An EDSL For Type-Safe SQL In C++ For Databases, Containers, Streams And More
  • Multithreading done right?
  • Testdriven C++ with Catch
  • The C++ Memory Model

The schedule will be online around the beginning of June.

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 "->"?