std::array
std::array
is a fixed-size container that wraps around a traditional C-style array. If you’re coming from a C background or even early C++, you’ll be familiar with the headaches of raw arrays—the lack of bounds-checking, the cumbersome syntax, and more. With std::array
, you get all the benefits of a traditional array, such as static memory allocation and constant-time access, while enjoying modern C++ amenities including range-based for-loops and member functions for size checking. Use std::array
when you know the size of your dataset in advance, and it will not change. It’s perfect for scenarios where performance is paramount and your memory needs are static.
Note
For more information on CPP core guidelines, please refer to C++ Core Guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
Purpose and suitability
std::array
is a container that encapsulates fixed-size arrays. Its strengths are as follows:
- Predictable...