Metaprogramming in C++ and in D

后端 未结 10 1937
生来不讨喜
生来不讨喜 2021-01-30 04:46

The template mechanism in C++ only accidentally became useful for template metaprogramming. On the other hand, D\'s was designed specifically to facilitate this. And apparently

10条回答
  •  故里飘歌
    2021-01-30 05:39

    Well in D you can easily impose static constraints on template parameters and write code depending on the actual template argument with static if.
    It's possible to simulate that for simple cases with C++ by using template specialization and other tricks (see boost) but it's a PITA and very limited cause the compiler doesn't expose many details about types.

    One thing C++ really just can't do is sophisticated compile time code generation.

提交回复
热议问题