C ++ constexpr重载,用于编译时和运行时的不同代码

the*_*ack 5 c++ optimization constexpr c++14

constexpr void X() {
  /* code, that can be executed at compiletime */
}

void X() {
  /* code, that does the same as above, but is optimized for runtime, eg.
  including caching, assembler code, ... to optimize runtime performance */
}
Run Code Online (Sandbox Code Playgroud)

如上所示,我想要两个函数,它们基本上都在做相同的事情,一个针对运行时进行了优化,一个针对编译时进行了优化。在我的示例中,运行时版本涉及缓存,这不能在constexpr中完成,但可以提高运行时的性能。

可以通过某种方式(使用C ++ 14)实现吗?

如果只能使用特定于编译器的解决方案来实现此目的,那么它们也可以,但是我更喜欢一种标准解决方案(当前,我不知道有一个解决方案)