Sorry if this was already discussed in the past, but I could not find any reference in the forum.
What is the reason not to define input stream operators in Juce? There are output stream operators, such as OutputStream::operator<<() but no InputStream::operator>>(). The same holds for String.
They can be very useful when some genericity is involved, e.g. when trying to input/output containers.
I would like to write something like:
template <class DataType>
OutputStream& operator<<(OutputStream& output, const Array<DataType>& array)
{
output << (int)array.size();
for (int i = 0; i != size; ++i)
output << array[i];
return output;
}
template <class DataType>
InputStream& operator>>(InputStream& input, Array<DataType>& array)
{
int size;
input >> size;
array.clearQuick();
array.ensureStorageAllocated(size);
for (int i = 0; i != size; ++i)
{
assert(!input.isExhausted());
DataType value;
input >> value;
array[i].add(value);
}
return input;
}
Since no operator>> are defined for builtin types, the second part does not work, even with Array. Of course, I could overload operator>> for builtins externally (delegating to readInt(), etc.), but I’m pretty sure there was a motivation for not encouraging things like this
No?