What is the effect of ordering if…else if statements by probability?

Specifically, if I have a series of if…else if statements, and I somehow know beforehand the relative probability that each statement will evaluate to true, how much difference in execution time does it make to sort them in order of probability? For example, should I prefer this: if (highly_likely) //do something else if (somewhat_likely) //do … Read more

Template default arguments

If I am allowed to do the following: template <typename T = int> class Foo{ }; Why am I not allowed to do the following in main? Foo me; But I must specify the following: Foo<int> me; C++11 introduced default template arguments and right now they are being elusive to my complete understanding. 6 Answers … Read more

Compelling examples of custom C++ allocators?

What are some really good reasons to ditch std::allocator in favor of a custom solution? Have you run across any situations where it was absolutely necessary for correctness, performance, scalability, etc? Any really clever examples? Custom allocators have always been a feature of the Standard Library that I haven’t had much need for. I was … Read more

STL or Qt containers?

What are the pros and cons of using Qt containers (QMap, QVector, etc.) over their STL equivalent? I can see one reason to prefer Qt: Qt containers can be passed along to other parts of Qt. For example, they can be used to populate a QVariant and then a QSettings (with some limitation though, only … Read more