Better way of enforcing this template?
- by Dennis Ritchie
Currently, I have a function template like this that converts a vector into a string (just a natural string, separating the elements with a comma):
//the type T must be passable into std::to_string
template<typename T>
std::string vec_to_str(const std::vector<T> &vec);
As you can see, this is only meant for vectors whose elements can be passed into the built-in std::to_string function (such as int, double, etc.)
Is it considered a good practice to document with comments the allowed T? If not, what should I do? Is it possible to enforce this in a better way?