There are several options for.
At first you could just provide a separate operator<<
overload for std::vector
, e. g.:
template <typename T>
std::ostream& operator<< (std::ostream& s, std::vector<T> const& v)
{ /* your generic implementation */ return s; }
It will then be called for every vector in your map:
os << it.first << " : " << it.second << "\n";
// ^ here...
I consider this the cleanest solution – but if it is too generic and you need something really different only for this specific map type, then you could either provide a separate overload for exclusively this type of map:
std::ostream& operator<<
(std::ostream& s, std::map<std::string, std::vector<int>> const& m)
{ /* your specific implementation */ return s; }
or, alternatively, specialise your operator for it:
template <>
std::ostream& operator<< <std::string, std::vector<int>>
(std::ostream& s, std::map<std::string, std::vector<int>> const& m)
{ /* your specific implementation */ return s; }