C++17: Core language features (part 1)

A u8 character literal

In C++17 was added new character literal for UTF-8.

For example:

It’s used for correct translation characters to ASCII on different platforms.


Hexadecimal floating point literals

In C++17 was added hexadecimal floating point literals.

Link for cppreference.

Continue reading “C++17: Core language features (part 1)”

C++17: Fold expressions

Fold expressions is the extension for already introduced variadic templates in C++11.

It allows to pack and unpack template parameters in unary and binary operations.

For example:

Example with pushing values:

Continue reading “C++17: Fold expressions”

C++17: new types: std::any, std::optional, std::variant


Any class can hold any type of object.  It’s type safe container for single values of any type.  A better way to handle any type and replace void*.

Type requeirments:

std::decay_t<T> – must be CopyConstructable


To get value from std::any you need to use std::any_cast.

In case if type in std::any_cast is wrong will be called std::bad_any_cast exception.

Continue reading “C++17: new types: std::any, std::optional, std::variant”

C++17: std::string_view

std::string_view it’s class which can view std::string or const char* without ownership and without additional memory requesting.

SSO (Small string optimization)

std::string has optimization for small strings ( compiler specific feature, for gcc, clang and msvc there are different values ).

For example for GCC 7.3 this value is 16 bytes. If string has <=16 bytes it will be saved in stack inside std::string object. If more then 16 bytes, then data used for saving string will be in heap. Which means additional memory allocations.

It can be checked by overloading operator new in global space.

Continue reading “C++17: std::string_view”