mercredi 25 août 2021

Overloading std::array << operator

I'm having trouble trying to overload operator << for std::array. I tried doing it casual way as for all other collections:

std::ostream& operator<<(std::ostream& os, std::array<int> const& v1)
{
    for_each(begin(v1), end(v1), [&os](int val) {os << val << " "; });
    return os;
}

But the compiler expects me to add information about the array's size, which would not make it a general solution for any integer array. I know that if I wanted to make it for genaral type I would have to use templates, but for now I just want to make it for array of integers.

Aucun commentaire:

Enregistrer un commentaire