4 ms·
I doubt that would help, since generic code is implicitly inline.
by marton78 5y ago
I doubt that would help, since generic code is implicitly inline.
- asdfasgasdgasdg 5y agoGeneric code has to be declared before use, in C++, if you're not predeclaring the types the template supports. But that is orthogonal to whether it is actually inlined in the generated code.
- missblit 5y agoAFAIK nothing requires generic code to be compiled inline in C++. Heck with explicit template instantiation the generic code may not even be in the same translation unit as the calling code. At that point it'd require link time optimization to inline it.
- im3w1l 5y agoNothing requires inline-specified code to be inlined either.
- nickysielicki 5y agoNot true! This is true in monomorphized languages like Rust, but C++ has vtables which allows for generic code at an assembly level. Maybe I’m misunderstanding you.
- jcelerier 5y agorun-time polymorphism is generally not called "generics"
- yakubin 5y agoWhat jcelerier said, but also as for: > This is true in monomorphized languages like Rust It's not necessarily true for monomorphized code. Inlining is enabled by monomorphization, but is not required. You can see it with templates in C++: function template instantiations aren't always inlined. They are instantiated in every TU separately, if they are defined in headers, but then they may be called in this TU just like any other function without inlining. This requires the linker to deduplicate the instantiations later. In another scenario you may declare a function template in a header without the implementation, putting the implementation in a CPP file along with explicit instantiation. In that case the compiler is not able to inline this function in another TU (without LTO). As for Rust, Rust is not universally monomorphized. The user of generic code in Rust gets to decide whether they want to use monomorphization or vtables, regardless of the ideas of the author of said generic code.
- nickysielicki 5y agoThanks for this comment, I have a lot to learn.
- chakkepolja 5y agoyou are talking about monomorphization. this thread is about function call inlining.