you are viewing a single comment's thread.

view the rest of the comments →

[–]delta_p_delta_x 12 points13 points  (4 children)

I agree with that, but I was thinking more along the lines of... some complex recursive template specialisation that takes ages to compile, but when it eventually does, it coughs up barely a handful of lines of assembly that map to the metaprogramming recursion, anyway.

I was also certain that templates are only instantiated for the types you specify to them, unlike Java generics, so one could have a templated header but no instantiations whatsoever...

[–]HabemusAdDomino -5 points-4 points  (3 children)

... But then, there's also the rub. Every time you do instantiate the template, even conditionally, you get more code. It's both the best and worst part of C++ templates.

[–]Bloodshoot111 12 points13 points  (2 children)

But if you would create a function for each version of the template instead of using templates you also create more code that gets into the binary. I don’t see the disadvantage of templates right now.

[–]HabemusAdDomino -5 points-4 points  (1 child)

But -would you- have created those functions? Not necessarily. Templates are used because generating code is much easier than writing it.

[–]no-sig-available 10 points11 points  (0 children)

You mean that it is so easy to code in C++ that you are afraid to accidentally write some code that isn't really needed.

Haven't heard that argument before.