On this page
std::array
Prev: std::optional | Up: containers | Next: std::span
Rel: std::vector, std::span
Ref: cppreference — std::array
Tags: #public #prog #cpp #stdlib #containers #tier/standard
Overview
std::array<T, N> (<array>) wraps a fixed-size, stack-allocated C array with zero overhead while providing .size(), .at(), value-copy semantics, and STL iterators—without silently decaying to a raw pointer.
Notes & Pitfalls
- Zero-overhead fixed-size stack array: Unlike C arrays,
std::arraynever decays to a raw pointer and knows its.size(). - Use
.at(i)for bounds-checked access ([]is unchecked).
Example
#include <array>
#include <cassert>
int main() {
std::array<int, 3> a{10, 20, 30};
assert(a.size() == 3 && a.at(1) == 20);
}
Linked from
Related notes
- tuts/cpp/stdlib/containers/optional Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/span Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/vector Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib
- tuts/cpp/stdlib/containers/expected shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/map shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/string shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/string_view shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/unordered_map shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/variant shared tags: #containers, #cpp, #prog, #stdlib, #tier