c++11 fast constexpr integer powers

后端 未结 2 1534
再見小時候
再見小時候 2020-12-17 18:51

Beating the dead horse here. A typical (and fast) way of doing integer powers in C is this classic:

int64_t ipow(int64_t base, int exp){
  int64_t result = 1         


        
2条回答
  •  一个人的身影
    2020-12-17 19:03

    It seems that this is a standard problem with constexpr and template programming in C++. Due to compile time constraints, the constexpr version is slower than a normal version if executed at runtime. But overloading doesn't allows to chose the correct version. The standardization committee is working on this issue. See for example the following working document http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3583.pdf

提交回复
热议问题