Comment

Comment by ho_schi

    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#Cl...

https://en.cppreference.com/w/cpp/language/function_template...

parent ho_schi 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton