Curried Objects in C++—Jonathan Boccara

Abstraction to the rescue.

Curried Objects in C++

by Jonathan Boccara

From the article:

Curried objects are like facilitators. They consist in intermediary objects between a caller and a callee, and helps them talk to each other in a smooth way. This ability makes the code simpler and easier to read...

Quick Q: What are copy elision and return value optimization?

Quick A: a way to remove copying objects in certain case, improving performance and reducing the constraints on a class (no copy or move needed).

Recently on SO:

What are copy elision and return value optimization?

Copy elision is an optimization implemented by most compilers to prevent extra (potentially expensive) copies in certain situations. It makes returning by value or pass-by-value feasible in practice (restrictions apply).

It's the only form of optimization that elides (ha!) the as-if rule - copy elision can be applied even if copying/moving the object has side-effects...

The Rule of Zero in C++—Jonathan Boccara

What's your opinion?

The Rule of Zero in C++

by Jonathan Boccara

From the article:

Now that we’re clear on the Compiler-generated Functions, the Rule of Three and the Rule of Five, let’s put this to use to reflect on how to use the “= default” feature to have expressive and correct code...

Quick Q: Reusing a moved container?

Quick A: clear() to make sure and use it as normal.

Recently on SO:

Reusing a moved container?

From section 17.3.26 of the spec "valid but unspecified state":

an object state that is not specified except that the object’s invariants are met and operations on the object behave as specified for its type [ Example: If an object x of type std::vector<int> is in a valid but unspecified state, x.empty() can be called unconditionally, and x.front() can be called only if x.empty() returns false. —end example ]

Therefore, the object is live. You can perform any operation that does not require a precondition (unless you verify the precondition first).

clear, for example, has no preconditions. And it will return the object to a known state. So just clear it and use it as normal.

The Day I Fell in Love with Fuzzing—Chris Wellons

Do you know about it?

The Day I Fell in Love with Fuzzing

by Chris Wellons

From the article:

In 2007 I wrote a pair of modding tools, binitools, for a space trading and combat simulation game named Freelancer. The game stores its non-art assets in the format of “binary INI” files, or “BINI” files. The motivation for the binary format over traditional INI files was probably performance: it’s faster to load and read these files than it is to parse arbitrary text in INI format...

How to Emulate the Spaceship Operator Before C++20 with CRTP—Henrik Sjöström

To wait until the real thing.

How to Emulate the Spaceship Operator Before C++20 with CRTP

by Henrik Sjöström

From the article:

Making a class comparable is usually something of a chore. In C++20 we’ll get the “three-way comparison operator” or informally spaceship operator <=>. It will allow the compiler to create comparison operators when we want a simple lexicographical comparison and when we have a more complex comparison we only need to implement a single operator to be able to do all comparisons...

Quick Q: C++ template typedef

Quick A: Use the normal template declaration.

Recently on SO:

C++ template typedef

C++11 added alias declarations, which are generalization of typedef, allowing templates:

template <size_t N>
using Vector = Matrix<N, 1>;

The type Vector<3> is equivalent to Matrix<3, 1>.

Quick Q: Compile-time loop optimisation

Quick A: each release of C++ allows more things to be done at compile time.

Recently on SO:

Compile-time loop optimisation

In C++14, constexpr function requirements were relaxed.

Previously, in C++11, constexpr functions could only contain typedefs, static_asserts and usings, but only a single return statement.

In C++14, it became possible to use loops in constexpr function bodies.

Because b was declared as constexpr char, it must be evaluated at compile time. The compiler then optimised out the isStringNice function, as it is not used at run time.

C++ Insights - Implicit Conversions—Andreas Fertig

A good tool!

C++ Insights - Implicit Conversions

by Andreas Fertig

From the article:

This series is motivated by a brief conversation I had with Andreas. I asked him if he has some use case examples which show how C++ Insights can be helpful when teaching. I think there are many things. This article is the start of a series of five posts by Andreas which I will publish at Modernes C++ because I think C++ Insights is an invaluable tool to get a deeper insight in the C++ compiler magic. In case, you are new to C++ Insights consider this introductory article. Without further ado, Andreas post. When you follow the link near to each example, you can directly analyse the example in C++ Insight...