Hacker News new | ask | show | jobs
by pg314 3360 days ago
> qsort might be general in the element type, but not in the container type.

That is a clear advantage of C++.

> Also without LTO it will be very expensive as it cannot inline the compare function call.

Templates force you to expose the implementation in a header file. In C you can choose. If you move the qsort implementation in a header file, the compiler should not have any trouble inlining it.

Inlining is not always a win, though (slower compiles, bigger code, more cache misses).

1 comments

Modules are supposed to fix this issue in some upcoming version of C++ standard.
That has been the case for the last 10 years. A module system for C++ is long overdue.