Articles & Books

How to Use the STL With Legacy Output Collections—Jonathan Boccara

And how back_inserter works.

How to Use the STL With Legacy Output Collections

by Jonathan Boccara

From the article:

When you start using the STL and its algorithms in your code, it’s a bit of a change of habits. And then after a while you get used to it. Then it becomes a second nature. And then even your dreams become organized into beautifully structured ranges that fly in and out of well-oiled algorithms.

And when you reach that point, there is no coming back.

Until the day you come upon an old legacy structure that won’t let itself approached by the elegant and expressive way of coding that STL algorithms have. It’s a terrible encounter, where the beast tries to suck you back into the lengthy and dangerous quicksand of the raw for loops that now seemed so far away...

Trip Report: C++ Standards Meeting in Albuquerque, November 2017—Botond Ballo

A thorough and detailed summary of the recent six-day meeting.

Trip Report: C++ Standards Meeting in Albuquerque, November 2017

by Botond Ballo

From the article:

A couple of weeks ago I attended a meeting of the ISO C++ Standards Committee (also known as WG21) in Albuquerque, New Mexico. This was the third committee meeting in 2017; you can find my reports on previous meetings here (February 2017, Kona) and here (July 2017, Toronto). These reports, particularly the Toronto one, provide useful context for this post.

With the final C++17 International Standard (IS) having been voted for publication, this meeting was focused on C++20, and the various Technical Specifications (TS) we have in flight, most notably Modules...

Simplifying Compile-Time Options With if constexpr—Philippe Groarke

New possibilities open in front of us!

Simplifying Compile-Time Options With if constexpr

by Philippe Groarke

From the article:

My latest little experiment relates to compile-time options and eliminating preprocessor checks in user code. I’m not a big fan of MACROs, especially when they are simply used to make compile-time branches. I am also not a fan of other techniques used to minimize this problem. With C++17, we now have a beautiful and simple tool that can help remove all these preprocessor checks, if constexpr...

Implementing the spaceship operator for optional—Barry Revzin

The future implementation?

Implementing the spaceship operator for optional

by Barry Revzin

From the article:

Last week, the C++ Standards Committee added operator<=>, known as the spaceship operator, to the working draft for what will eventually become C++20. This is an exciting new language feature for two reasons: it allows you to write one function to do all your comparisons where you used to have to write six, and it also allows you to write zero functions — just declare the operator as defaulted and the compiler will do all the work for you! Exciting times...

First Meeting C++ Trip Report—Simon Brand

Simon Brand attended the recent Meeting C++ conference and wrote down his impressions:

Meeting C++ Trip Report

by Simon Brand

From the article:

This year was my first time at Meeting C++. It was also the first time I gave a full-length talk at a conference. But most of all it was a wonderful experience filled with smart, friendly people and excellent talks. This is my report on the experience. I hope it gives you an idea of some talks to watch when they’re up on YouTube, and maybe convince you to go along and submit talks next year! I’ll be filling out links to the talks as they go online.


CppCon2017 Trip Report—Gordon Brown

Trip report from CppCon 2017. Highlights, trends and some tips for getting the most out of the conference.

CppCon2017 Trip Report

by Gordon Brown

From the article:

CppCon this year was bigger than ever with approaching 1200 attendees and 7 tracks; making it even harder to pick which talks to go to. Thankfully all the talks are made available online, so if you couldn’t make it to the conference or even if you did but couldn’t get to see all the talks you wanted to, you can go online and watch them. I only got to a handful of the talks as I often had conflicting appointments, but I’ve highlighted a few from what I saw that I would recommend checking out and some which I didn’t make it to but heard good things about.

Quick Q: What is the usefulness of `enable_shared_from_this`?

Quick A: It allows you to get a valid shared pointer from your instance directly.

Recently on SO:

What is the usefulness of `enable_shared_from_this`?

It enables you to get a valid shared_ptr instance to this, when all you have is this. Without it, you would have no way of getting a shared_ptr to this, unless you already had one as a member. This example from the boost documentation for enable_shared_from_this:

class Y: public enable_shared_from_this<Y>

    shared_ptr<Y> f()
        return shared_from_this();

int main()
    shared_ptr<Y> p(new Y);
    shared_ptr<Y> q = p->f();
    assert(p == q);
    assert(!(p < q || q < p)); // p and q must share ownership

The method f() returns a valid shared_ptr, even though it had no member instance. Note that you cannot simply do this:

class Y: public enable_shared_from_this<Y>

    shared_ptr<Y> f()
        return shared_ptr<Y>(this);

The shared pointer that this returned will have a different reference count from the "proper" one, and one of them will end up losing and holding a dangling reference when the object is deleted.

enable_shared_from_this is going to be a part of the new C++0x standard as well, so you can also get it from there as well as from boost.

Abstraction design and implementation: `repeat`—Vittorio Romeo

This series of two articles covers the train of thought behind the design and implementation of a simple `repeat` abstraction that, given a number `n` and a function object `f`, invokes `f` `n` times. The abstraction can be used to repeat actions both at run-time and compile-time. The articles also cover importance of propagating `noexcept`-correctness (and the pain caused by it!).

abstraction design and implementation: `repeat`

compile-time `repeat` & `noexcept`-correctness

by Vittorio Romeo

From the articles:

In my previous "passing functions to functions" and "zero-overhead C++17 currying & partial application" articles I've praised C++11 (and newer standards) for allowing us to write "more functional" code. [...] If I want to repeat an action n times, I exactly want to write that in my code:

    repeat(10, []

Cannot get simpler than that - let's implement it!

2017 Albuquerque ISO C++ Committee Reddit Trip Report

Another report:

2017 Albuquerque ISO C++ Committee Reddit Trip Report

From the article:

The ISO C++ Committee met in Albuquerque, New Mexico, USA last week to continue work on C++ Technical Specifications and the next International Standard, C++20. C++17 is done; the final version was sent to ISO for publication in September. We started to firm up the schedule and feature set for C++20 at this meeting; we're hoping to land most of the major features by the first meeting of 2019...