c++qtoperator-overloadingqdatastream

QDataStream custom writing - one vs multiple lines;


I'll write a custom operator for my struct, and I'm wondering if there is any difference in performance between the two:

QDataStream &operator<<(QDataStream &out, const Event &event)
{
    out << event.a;
    out << event.b;
    out << event.c;
}

QDataStream &operator<<(QDataStream &out, const Event &event)
{
    out << event.a
        << event.b
        << event.c;
}

Solution

  • QDataStream operator<< overloads return a reference to the QDataStream object so there's no appreciable performance difference between the two (your snippets would likely result in the same generated code).

    Use whichever you feel makes your code more readable.