Favourite C++ features

C++17

C++20

Concepts

C++20 gives us language support (new keywords - requires, concept) and a set of predefined concepts from the Standard Library.

In other words, you can restrict template parameters with a “natural” and easy syntax. Before C++20, there were various ways to add such constraints. See my other post Simplify Code with if constexpr and Concepts in C++17/C++20 - C++ Stories.

https://www.cppstories.com/2021/concepts-intro/

template <typename T>
void print(const std::vector<T>& vec) {
for (size_t i = 0; auto& elem : vec)
std::cout << elem << (++i == vec.size() ? "n" : ", ");
}
void print2(const std::vector<auto>& vec) {
for (size_t i = 0; auto& elem : vec)
std::cout << elem << (++i == vec.size() ? "n" : ", ");
}

Ranges and views

The ranges library provides components for dealing with ranges of elements, including a variety of view adapters: immutable views of things; a nod to strongly typed, const languages like Haskell, composing syntax.

Coroutines

A new stackless threading model that also allows lazy evaluation of infinite sequences.

Misc

Wish list

See the compiler support matrix.

Modules

Look interesting but not available until clang-12.