
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Library -
The
This header is part of the containers library and also optimized for performing critical applications, can be used with different data layouts such as (row-major, column-major order).
Including Header
To include the
#include
Functions of Header
Below is list of all functions from
S.No | Functions & Description |
---|---|
1 |
operator []
This function accesses an element at the specified multidimensional index. |
2 |
size
This function returns the size of the multidimensional index space. |
3 |
empty
This function checks if the size of the index space is zero. |
4 |
stride
This function obtains the stride along the specified dimension. |
5 |
extents
This function obtains the extents object. |
6 |
data_handle
This function obtains the pointer to the underlying 1D sequence. |
7 |
mapping
This function obtains the mapping object that defines how multidimensional indices map to the 1D data. |
8 |
accessor
This function returns the accessor policy object, which manages access to the underlying element. |
Accessing Elements
In the following example we are going to use, operator[] it allows matrix[1][2] accesses the element at the first row and second column.
#include#include int main() { std::array data = {1, 2, 3, 4, 5, 6, 7, 8, 9}; std::mdspan > matrix(data.data()); std::cout << "Element at [1][2]: " << matrix[1][2] << std::endl; return 0; }
Output
If we run the above code it will generate the following output
6
Property Checks
The property checks are member functions that provide information about how the multidimensional mapping of the object behaves.
S.No | Functions & Description |
---|---|
1 |
is_unique
This function determines if this mdspan's mapping is unique. |
2 |
is_exhaustive
This function determines if this mdspan's mapping is exhaustive. |
3 |
is_strided
This function determines if this mdspan's mapping is strided( in each dimension, incrementing an index jumps over the same number of underlying elements every time). |
Property Checking
In the following example we are going to use, is_unique() function to check if each multidimensional index in the mdspan maps to a distinct element in the 1D data array.
#include#include int main() { std::array data = {1, 2, 3, 4, 5, 6, 7, 8, 9}; std::mdspan > matrix(data.data()); if (matrix.is_unique()) { std::cout << "Mapping is unique." << std::endl; } else { std::cout << "Mapping is not unique." << std::endl; } return 0; }
Output
If we run the above code it will generate the following output
Mapping is unique.
Static Functions
The static functions provides compile-time properties of mdspan and its mapping layout.
S.No | Functions & Description |
---|---|
1 |
is_always_unique
This static function determines if this mdspan's layout mapping is always unique. |
2 |
is_always_exhaustive
This static function determines if this mdspan's layout mapping is always exhaustive. |
3 |
is_always_strided
This static function determines if this mdspan's layout mapping is always strided. |
Checking Compile-Time Property
In the following example we are going to use, is_always_exhaustive to check if the layout mapping always covers the entire extents of the mdspan in a contiguous manner at compile-time.
#include#include int main() { if (std::mdspan >::is_always_exhaustive()) { std::cout << "Mapping is always exhaustive." << std::endl; } else { std::cout << "Mapping is not always exhaustive." << std::endl; } return 0; }
Output
If we run the above code it will generate the following output
Mapping is always exhaustive.