小编Thi*_*eel的帖子

无需模板即可优化特定参数

我遇到了一些速度很快的优化代码,但它使我的代码变得丑陋。

一个最小的例子如下:


enum class Foo : char {
    A = 'A',
    B = 'B'
};

struct A_t {
    constexpr operator Foo() const { return Foo::A; }
};

void function_v1(Foo s){
   if(s == Foo::A){
      //Run special version of the code
   } else {
      //Run other version of the code
   }
}

template<class foo_t>
void function_v2(foo_t s){
   if(s == Foo::A){
      //Run special version of the code
   } else {
      //Run other version of the code
   }
}

int main(){

   // Version 1 …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-optimization

0
推荐指数
1
解决办法
104
查看次数

标签 统计

c++ ×1

compiler-optimization ×1