3 ms·
For full builds, C++ will take longer to compile than Rust (i.e. Rust wins). This is because of C++'s #include feature and C++ templates, which nee
by ho_schi 4y ago
For full builds, C++ will take longer to compile than Rust (i.e. Rust wins).
This is because of C++'s #include feature and C++
templates, which need to be compiled once per .cpp file.
This compilation is done in parallel, but parallelism is
imperfect.
The author gives later on within the article a hint upon "and externing template instantiations". This allows to compile a template just once with a given set of template arguments. Shall reduce reduce compile-time. I assume it also reduces size of created object-files?
Explicit instantiation of templates is supported since C++11. Therefore templates with one set of template arguments can be are declared in multiple files and defined just once - in one file. The keyword for this is extern upon each declaration. Please note, that all member of a template will be instantiated whether used or not. The user "strager" mentioned that briefly.
see:
https://en.cppreference.com/w/cpp/language/class_template#Class_template_instantiation https://en.cppreference.com/w/cpp/language/class_template#Cl...
https://en.cppreference.com/w/cpp/language/function_template#Function_template_instantiation https://en.cppreference.com/w/cpp/language/function_template...
- strager 4y ago> I assume it also reduces size of created object-files? Normal template instantiations are deduplicated by the linker. Total object file size is smaller with explicit template instantiations, but the size of the final executable is the same with both styles.
- ho_schi 4y agoWow. Thanks :)