When does template instantiation bloat matter in practice?

前端 未结 5 840
忘了有多久
忘了有多久 2021-01-02 00:56

It seems that in C++ and D, languages which are statically compiled and in which template metaprogramming is a popular technique, there is a decent amount of concern about t

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 01:37

    Template bloat is NOT an issue (It is a mental problem not a code problem).

    Yes it can get big. But what's the alternative?
    You could write all the code yourself manually (once for each type). Do you think writting it manually will make it smaller. The compiler only instanciate the versions it actually needs and the linker will remove multiple copies spread over compilation units.

    So there is no actual bloat.
    It is just building what you use. If you use a lot of different types you need to write more code.

提交回复
热议问题