I would like to have separate specializations for a function when the type is a container vs. non-container types. For example:
template <typename T>
void print(const T& t) {
cout << "non-container: " << t;
}
template <>
void print(const ContainerType& container) {
cout << "container: ";
for (const auto& t : container) {
cout << t;
}
}
Then I could use these functions like:
print(3); // Prints non-container: 3
print(vector{1, 1, 2}); // Prints container: 1 1 3
print(set{1, 1, 2}); // Prints container: 1 2
I don't know how to specify the specialization of print so that it will get called for vector
and set
but not for int. I don't want to have to create separate specializations for every container type I want a single specialization for any iterable type.