klickverbot wrote:
Max Samukha wrote:
I think the following real-world code is a good argument against comma
operators:
template <typename T>
Q_INLINE_TEMPLATE void QList<T>::node_destruct(Node *from, Node *to)
{
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
while(from != to) --to, delete reinterpret_cast<T*>(to->v);
else if (QTypeInfo<T>::isComplex)
while (from != to) --to, reinterpret_cast<T*>(to)->~T();
}
I have never used the comma operator in my own code, but in my opinion this
particular piece of code is really easy and fluent to read.
»Maintainability« is admittedly, however, a different topic.
It is still more readable than 'while(from != to--)' or '((--to)->v)'.
I myself use the comma operator in for loops and simple assignments such
as 'if(something) x = a, y = b;'.
The boost::assign namespace also declares operator,() overloads to ease
up assignments in C++ such as 'myVector += 1,2,3,4,5;'.