#include template class Array { private: int m_capacity = 0; T* m_data = nullptr; public: Array(int capacity) : m_capacity(capacity), m_data(new T[capacity]{}) { } ~Array() { delete[] m_data; } T& operator[](int index) { return m_data[index]; } friend std::ostream& operator<< (std::ostream& stream, const Array& array) { for (int i = 0; i <= array.m_capacity - 1; i++) { // how can i check in here if value under this key contains something that user set manually? stream << i << ": " << array.m_data[i] << std::endl; } return stream; } }; int main() { Array test = Array(5); test[0] = 1; test[1] = 0; // this 0 should be also displayed test[2] = 3; /* result right now: 0: 1 1: 0 2: 3 3: 0 4: 0 what i would like to achieve: 0: 1 1: 0 2: 3 so as you can see i would like to not display element 3,4 because i haven't set these values. */ std::cout << test << std::endl; std::getchar(); return 0; }