constexpr在我看来,C++ 11的功能,以及模板参数包应该足够强大,可以执行一些相当复杂的计算.我有一个实际应用的一个可能的例子是在编译时计算第n个素数.
constexpr
我在想办法实现这个计算.如果提出了多个解决方案,那么比较它们可能会很有趣.
为了让你了解我的性能预期:我希望有一些代码可以在合理的桌面硬件上在不到一秒的编译时间内找到第512个素数(即3671).
c++ compile-time template-meta-programming constexpr c++11
c++ ×1
c++11 ×1
compile-time ×1
constexpr ×1
template-meta-programming ×1