Articles & Books

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.

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

 

 

A serious bug in GCC -- Andrzej Krzemienski

In his recent blog post Andrzej described in detail about a bug he discovered in GCC.


A bug in GCC

by Andrzej Krzemienski

From the article:

This post is to inform you about a bug in GCC that may cause memory (or other resource) leaks in your valid C++ programs.

One of the pillars of C++ philosophy is what we often call RAII: if you use classes to manage resources, use constructors for allocating resources and destructors for releasing them, the language makes sure that whatever happens, however you use such classes the resources will get properly released.

 

Quick Q: Syntax of final, override, const with trailing return types

Quick A: The signature of the function is first.

Recently on SO:

Syntax of final, override, const with trailing return types

The correct syntax should be:

  • override and final should appear after the member function declaration, which including the trailing return type specification, i.e.
auto debug(ostream& os=cout) const ->ostream& override final;
  • override and final should not be used with the member function definition outside the class definition, so just remove them:
auto Derived::debug(ostream& os) const ->ostream&
{
  os << "dval: " << dval << endl;
  return os;
}

Overload 138 is now available

ACCU’s Overload journal of April 2017 is out. It contains the following C++ related articles.

Overload 138 is now available

From the journal:

Breadth First, Depth First, Test First
You can approach a problem top-down or bottom-up. Frances Buontempo wonders if algorithms can help us choose the most appropriate direction. by Frances Buontempo

Space invaders in Elm
Elm is a functional language which compiles to JavaScript. Ossi Hanhinen provides an overview. by Ossi Hanhinen

Single Module Builds – The Fastest Heresy in Town
Unity builds can be controversial. Andy Thomason shows how much difference they can make to build times. by Andy Thomason

An Interview: Emyr Williams
CVu has been running a series of interviews. Frances Buontempo interviews the interviewer, Emyr Williams. by Frances Buontempo

(Not Really So) New Niche for C++: Browser!?
How do you run C++ in a browser? Sergey Ignatchenko demonstrates how to use Emscripten. by Sergey Ignatchenko

Contractual Loopholes
Compilers can optimise away functions you may want to time. Deák Ferenc explores ways to stop this happening. by Deák Ferenc

All About the Base
Representing numbers presents many choices. Teedy Deigh counts the ways. by Teedy Deigh

C++ Jobs and Predictions -- Bartlomiej Filipek

Is C++ job market falling or growing? Since billions of lines of code are already written it's not possible to disappear in a second. So what's the current state and the future?

C++ Jobs and Predictions

by Bartlomiej Filipek

From the article:

... if you like this area you'll be able to find a C++ job anyway. I hope C++20 will add another good reason to stick with C++ and even move from other languages... but we need to wait a few years to see it happening.

Understand ranges better with the new Cartesian Product adaptor--Jonathan Boccara

The future explained:

Understand ranges better with the new Cartesian Product adaptor

by Jonathan Boccara

From the article:

A couple of days ago, the range-v3 library got a new component: the view::cartesian_product adaptor.

Understanding what this component does, and the thought process that went through its creation is easy and will let you have a better grasp of the range library. (Note that you could just as well understand all the following by looking at the zip adaptor. But cartesian_product is brand new, so let’s discover this one, in order to hit two birds with one stone)...