May 2017

A true heterogeneous container in C++--Andy G

An interesting article as well as a nice demo!

A true heterogeneous container in C++

by Andy G

From the article:

Oftentimes I see questions StackOverflow asking something to the effect of

“Can I have a std::vector that holds more than one type?”
The canonical, final, never-going-to-change answer to this question is a thorough

“No”
C++ is a statically-typed language. A vector will hold an object of a single type, and only a single type.

“But…”
Of course there are ways to work around this...

Quick Q:Is there a way to mark a parent's virtual function final from a child class?

Quick A: No.

Recently on SO:

Is there a way to mark a parent's virtual function final from a child class without reimplementing it

No, you can't do it without reimplementing it. So just reimplement it:

struct Child : public Parent
{
    virtual void fn() override final { Parent::fn(); }
};

N.B. saying virtual ... override final is entirely redundant, final is an error on a non-virtual function, so you should just say:

    void fn() final { Parent::fn(); }

See http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override

Registration for CppCon 2017 is Open

The next CppCon conference is in Bellevue, Washington September 24-29.

Registration for CppCon 2017 is Open

From the announcement:

In addition to the regular conference program there will be keynotes, lightning talks, and panels. There are also twelve pre- and post-conference classes (both two-day and one-day are offered) as well as a field trip to Boeing's Future of Flight tour.

C++ User Group Meetings in May

The monthly C++ User Group listing at Meeting C++:

C++ User Group Meetings in May 2017

by Jens Weller

From the article:

The monthly overview on upcoming C++ User Group Meetings. Lots of meeting are already planned for May, even more should be announced in the coming weeks.

There are 2 new C++ User Groups: Minneapolis, Stockholm (LLVM).

Quick Q: shrink_to_fit() vs swap trick

Quick A: Are equivalent, but shrink_to_fit mark the intention.

Recently on SO:

shrink_to_fit() vs swap trick

The swap trick isn't actually constant-time. The cost of performing the actual swap is indeed O(1), but then there's the cost of the std::vector destructor firing and cleaning up all the allocated space. That can potentially have cost Ω(n) if the underlying objects have nontrivial destructors, since the std::vector needs to go and invoke those destructors. There's also the cost of invoking the copy constructors for all the elements stored in the initial vector, which is similarly Ω(n).

As a result, both approaches should have roughly the same complexity, except that shrink_to_fit more clearly telegraphs the intention and is probably more amenable to compiler optimizations.

Continuous integration with Travis CI--Richel Bilderbeek

A very useful tool:

Continuous integration with Travis CI

by Richel Bilderbeek

From the article:

In today’s guest post, Richel Bilderbeek gives us some insight about some the many possible advantages of setting up a continuous integration service, showing some minimal complete examples. Richel works as a PhD in Theoretical Biology at the University of Groningen industry, in his free time teaching people from ages 7-77 about C++, Processing, Arduino and R. Falling inexplicably in love with a C++ code snippet of Doom as a kid, he started using C++ only since 2001, and you can reach him through his website...

QStringView Diaries: Masters Of The Overloads -- Marc Mutz

The third episode of the QStringView Diaries blog series is out, in which Qt developer Marc Mutz describes the ongoing work in implementing a string-view for QString data.

QStringView Diaries: Masters Of The Overloads

by Marc Mutz

From the article:

The last blog post in this series described how to use string-views. This post is about how to design one. In particular, it’s about QStringView‘s constructors. They evolved through a rapid succession of changes. These changes either fixed ambiguities between QString and QStringView overloads, or improved performance. And they all have the same solution: std::enable_if, the Swiss Army Knife for overload control.

This post will take you from where we naïvely started to where we made the impossible possible: overloading a function for arrays and pointers.

In case you missed them, here are the first two instalments:

QStringView Diaries: The Eagle Has Landed

QStringView Diaries: Advances in QStringLiteral