...

/

The Standard Library

The Standard Library

Get a brief overview of what the standard library of C++20 has to offer.

std::span

A std::span represents an object that can refer to a contiguous sequence of objects. A std::span, sometimes also called a view, is never an owner. This view can be a C-array, a std::array, a pointer with a size, or a std::vector. A typical implementation of a std::span needs a pointer to its first element and a size.

The main reason for having a std::span is that a plain array will decay to a pointer if passed to a function; therefore, its size is lost. std::span automatically finds the size of an array, a std::array, or a std::vector. If you use a pointer to initialize a std::span, you have to provide the size in the constructor.

Press + to interact
void copy_n(const int* src, int* des, int n){}
void copy(std::span<const int> src, std::span<int> des){}
int main(){
int arr1[] = {1, 2, 3};
int arr2[] = {3, 4, 5};
copy_n(arr1, arr2, 3);
copy(arr1, arr2);
}

Container improvements

C++20 has many improvements ...