In the reference example, a cycle is specified for the Q_LIKELY macro and a situation is considered when the false state can occur, as they say, in one case per million:
// the condition inside the "if" will be successful most of the times for(int i = 1; i <= 365; i++) { if(Q_LIKELY(isWorkingDay(i))) { ... } ... } In general, this benefit can be seen, taking into account not uncommon situations when a value is checked in a cycle, meaning that it is only in one of two states, and one of them will almost always be in the overwhelming majority of cases.
But the example for Q_UNLIKELY , although, judging by the name, it is just the opposite:
bool readConfiguration(const QFile &file) { // We expect to be asked to read an existing file if(Q_UNLIKELY(!file.exists())) { qWarning() << "File not found"; return false; } ... return true; } What can there be "help to the compiler" in optimizing the code, and if it does take place, will it be fair for Q_LIKELY ? Maybe there are some criteria for determining the characteristic situations in which the use of these macros makes sense?