I was working on a print()
function in C++ and was wondering:
template <typename BaseType>
void print(BaseType data, bool newline = false, bool raw = false) {
// Standard > C Out
std::cout << data;
/* Logic
If
Newline is true.
*/
if (newline)
std::cout << std::endl;
};
What if this same function could react differently to arrays and print out each individual member of the array rather than give back a value like 0x22fe30
?
Something like:
print("Hello, World!"); // prints "Hello, World!"
print(array); // prints "[1, 0, 1]"
I'm only doing this for fun to see how far my skills in C++ really are and would appreciate any helpful answer. Thanks.