CopperSpice: C++ Tapas

New video on the CopperSpice YouTube Channel:

C++ Tapas

by Barbara Geller and Ansel Sermersheim

About the video:

This video discusses an assortment of related topics including typedefs, type aliases, namespaces, and forward declarations. We talk about how all these fundamental pieces of C++ program structure interact and how their usage and C++ idioms have changed over time.

Please take a look and remember to subscribe!

How to Reorder A Collection With the STL--Jonathan Boccara

Did you know?

How to Reorder A Collection With the STL

by Jonathan Boccara

From the article:

The STL lets you do plenty of things on collections, and one of them is to reorder the elements inside of the collection. Or, said another way, to perform a permutation on the collection.

Inded, moving elements around a collection typically takes a fair amount of complex code to write, involving for loops and iterators. And it is perhaps the area where the STL generates the most spectacular improvements, by encapsulating those complex operations behing meaningful interfaces.

Let’s see what sorts of permutations the STL offers:

  • Lexicographical permutations
  • Cyclic permutations
  • Random permutation
  • Reverse
  • Checking for permutations
  • Other permutations

Quick Q: int a[] = {1,2,}; Weird comma allowed. Any particular reason?

Quick A: For convenience.

Recently on SO:

int a[] = {1,2,}; Weird comma allowed. Any particular reason?

It makes it easier to generate source code, and also to write code which can be easily extended at a later date. Consider what's required to add an extra entry to:

int a[] = {
   1,
   2,
   3
};

... you have to add the comma to the existing line and add a new line. Compare that with the case where the three already has a comma after it, where you just have to add a line. Likewise if you want to remove a line you can do so without worrying about whether it's the last line or not, and you can reorder lines without fiddling about with commas. Basically it means there's a uniformity in how you treat the lines.

Now think about generating code. Something like (pseudo-code):

output("int a[] = {");
for (int i = 0; i < items.length; i++) {
    output("%s, ", items[i]);
}
output("};");

No need to worry about whether the current item you're writing out is the first or the last. Much simpler.

optional in Containers Ⅱ — Not All std::vector Usages Are The Same--Jonathan Müller

What do you think?

optional<T> in Containers Ⅱ — Not All std::vector Usages Are The Same

by Jonathan Müller

From the article:

Okay, so in the previous post I talked about putting optional<T> in container. I came to conclusions which I though were reasonable at the time, however, people — rightfully — pointed out some flaws in my argumentation...

ACCU 2018 trip report -- Mathieu Ropert

Mathieu describes his impressions from the recent ACCU conference in

ACCU 2018 trip report

by Mathieu Ropert

From the article

It’s great to see that the British had an association with quality conferences and publications for so long. In comparison France only has (to my knowledge) a couple of for-profit magazines on programming that never struck me as worth mentioning. As for conferences, of course we have the great Paris User Group but we fall short in terms of native languages conferences.

 

CppCast Episode 146: CppDock and Nbdl with Jason Rice

Episode 146 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Jason Rice to discuss C++ Web Application Development and his libraries CppDock and nbdl.

CppCast Episode 146: CppDock and Nbdl with Jason Rice

by Rob Irving and Jason Turner

About the interviewee:

Jason Rice is a web applications programmer with an appetite for C++ metaprogramming having made small contributions to Boost.Hana. He is actively working on the library Nbdl, waiting for the day when C++ takes over the web.

compile-time iteration with C++20 lambdas -- Vittorio Romeo

This article covers various compile-time "iteration" constructs that rely on the upcoming "familiar template syntax for lambdas" C++20 feature.

compile-time iteration with C++20 lambdas

by Vittorio Romeo

From the article:

In this article I'm going to show you how to implement the above constructs, relying on a new nifty addition to C++20 lambdas: [P0428: "Familiar template syntax for generic lambdas"], by Louis Dionne. [...]

It shows how to implement constructs for the following operations:

Iterating over a list of types;
Iterating over a list of compile-time values;
Iterating over a compile-time integral range;
Enumerating a list of types alongside their indices.
The code provided works on g++ 8

ACCU 2018 Trip Report -- Felix Petriconi

The yearly conference of the ACCU just has taken place in Bristol, UK. It had three strong C++ tracks.

ACCU 2018 Trip Report

by Felix Petriconi

About the report

Felix describes his view on the conference from the perspective of a conference committee member.

How to Pass a Polymorphic Object to an STL Algorithm--Jonathan Boccara

Did you ever try?

How to Pass a Polymorphic Object to an STL Algorithm

by Jonathan Boccara

From the article:

As we can read in the opening chapter of Effective C++, C++ is a federation of 4 languages:

  • the procedural part coming from C,
  • the object-oriented part,
  • the STL part (following a functional programming paradigm),
  • the generic part with templates.

And what’s more, all of those 4 sub-languages are part of one whole: the C++ language. Those 4 paradigms begin united in one language gives opportunities for them to interact – and often, those interactions create interesting situations.

Today we’re focusing on one particular interaction, between the object-oriented model and the STL. There could be multiple forms for this interaction, and the case we will look at is how to pass a polymorphic (that is, having virtual methods) function object to an STL algorithm.