编译期编程
自从c++98开始,可以使用循环和路径选择执行的方式,在程序编译期执行计算。比如计算一个数是否为素数,可以使用如下的模板来实现:template<unsigned p, unsigned d>struct DoIsPrime{ static constexpr bool value = (p%d != 0) && DoIsPrime<p, d-1>::value;};template<unsigned p>struct DoIsPri
原创
2022-05-05 15:13:06 ·
420 阅读 ·
0 评论