intermediate

Template Specialization--Rainer Grimm

The series continue.

Template Specialization

by Rainer Grimm

From the article:

Templates define the behavior of families of classes or functions. Often it is required that special types or non-types may be treated special. To support this use case, you can specialize templates.

Template Argument Deduction of Class Templates--Rainer Grimm

The series continue.

Template Argument Deduction of Class Templates

by Rainer Grimm

From the article:

In my last post Template Arguments, I wrote about function template type deduction (C++98) and auto type deduction (C++11). Today I wear more modern hats. I start with automatic type deduction of non-type template parameters and class templates (C++17) and finish with automatic type deduction of concepts (C++20).

Reversing words of a string with ranges--Marco Arena

A new interpretation of a classical problem:

Reversing words of a string with ranges

by Marco Arena

From the article:

In this post I share the story of a “C++ aha-moment”, hence I use the hashtag #thatsarotate (resumed last Saturday at the Italian C++ Conference 2021 to honor our keynote speaker Sean Parent). Why not sharing your own stories of “C++ aha-moments” adding the same hashtag to your tweets, posts, or whatever? It would be really appreciated...

Quick Q: Overload resolution between object, rvalue reference, const reference

Quick A: the better match is picked, and an error generated if there none.

Recently on SO:

Overload resolution between object, rvalue reference, const reference

As there is only one parameter, the rule is that one of the three viable parameter initializations of that parameter must be a better match than both the other two. When two initializations are compared, either one is better than the other, or neither is better (they are indistinguishable).

Without special rules about direct reference binding, all three initializations mentioned would be indistinguishable (in all three comparisons)...

How to Insert Several Elements in a Vector (With No Memory Errors)--Jonathan Boccara

How do you do it?

How to Insert Several Elements in a Vector (With No Memory Errors)

by Jonathan Boccara

From the article:

Inserting elements in a vector sounds like the most basic use case we can think of when it comes to using collections in C++.

Nevertheless, this is a complex topic in itself, because std::vector offers various ways to insert several elements. Choosing the most appropriate depending on your exact use case allows to write more expressive code. And misusing the interface of std::vector can lead to memory errors.

Let’s navigate the various ways to insert several elements in a vector in a safe way, so that you can choose the one that fits best for your code...

Function Templates - More Details about Explicit Template Arguments and Concepts--Rainer Grimm

The series continue.

Function Templates - More Details about Explicit Template Arguments and Concepts

by Rainer Grimm

From the article:

In the last post "Function Templates", I wrote about the overloading of function templates and automatically deducing the return type of a function template. Today, I dive deeper and specify explicitly the template arguments of a function template and bring concepts into the play...

return first example--Marius Elvert

Clarifying.

return first example

by Marius Elvert

From the article:

It seems my “return first” post was not as enlightening as I had hoped. It was posted on reddit, and while the majority of commenters completely missed the point, it wasn’t really clear for those that did not just read the title. Either way, I am to blame for that – the examples and my reasoning were not very conclusive. So let me try clearing up the confusion with a better example...