Furthermore I bet the generic, templated version is as small and fast as a naive implementation. It's all templates so it's all static code generation.
Furthermore I bet the generic, templated version is as small and fast as a naive implementation. It's all templates so it's all static code generation.
I.e. a 200% increase in code size! Now imagine that throughout the entire code base.
> Is 2 lines not an accepted tradeoff for being able to change the engine, and crucially, to draw numbers from any distribution you want?
It is a complete waste if you don't need that functionality. That is the point. Generic solutions solve problems you don't even have, and that comes at a price.
>Furthermore I bet the generic, templated version is as small and fast as a naive implementation. It's all templates so it's all static code generation.
You kinda missed the point. I did not even specify how random(a,b) was implemented, so making statements about the speed of the compiled code makes no sense here.
C++'s templates are another nice example of the cost of generic code, though. They are one of the primary reasons why compiling C++ is so slow / resource intense. They have to be instantiated at compile-time again and again and again.. which is a non-trivial process, much slower to compile than a plain non-generic function call. Also they are historically infamous for producing hard to understand error messages.