Hongyuan Huang

"\x48\x48\x59\x26\x48\x58\x59\x3A\x44"

Modern C++ Tutorials #4: Containers

04 Containers

std::array

With a std::array, the element type and array length are part of the type information.

// Doesn't work:
// void printArray(const std::array& myArray);
// OK but limited use case:
// void printArray(const std::array<int, 5>& myArray);

template <typename T, std::size_t size>
void printArray(const std::array<T, size>& myArray)
{
    for (auto element : myArray)
        std::cout << element << ' ';
    std::cout << '\n';
}