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.
std::vector<int>? I doubt that you pursue performance of allocation thatstd::arrayis for, so it would be the easiest to use a dynamic-size arraystd::array<int>is not a type (asstd::array<int, 4>would be). You need to use a template instead of a normal function.for (const auto & val : v1) { os << val << " "; }would be more readable.