I am trying to understand how to declare a concept that requires a particular operator is overloaded for a given type. Lets say I have the following function that takes a vector of an arbitrary type and prints it to std::cout:
template<typename printable>
void print_vector(const std::vector<printable>& vec)
{
std::cout << '{';
for (const printable &item : vec) {
std::cout << item << ',';
}
std::cout << '}';
}
This code will work just fine if the type printable has an overloaded << operator, but if it doesn't, then it fails with a very unhelpful compiler error. I feel like I should be able to somehow declare a concept that requires a type has a valid << operator defined, and use that concept in the function declaration, so that I can get a more useful compiler error, but I haven't been able to figure out how to do it.