參數值遞歸模版類

#include <iostream>
#include <map>

namespace teaflow {
template<std::size_t...> struct seq{
  void pint() {
    std::cout << "origin seq" << std::endl;
  }
};

template<int N, int... Is>
struct CE : CE<N-1, N, Is...>{
};

template<int... N>
struct CE<0, N...> : seq<N...> {
  void pint() {
    std::cout << "0" << std::endl;
  }
};

template<int... N>
struct CE<1, 2, N...> : seq<N...> {
  void pint() {
    std::cout << "1 2" << std::endl;
  }
};

template<int... N>
struct CE<1, 1, N...> : seq<N...> {
  void pint() {
    std::cout << "1 1" << std::endl;
  }
};

}



int main() {
  teaflow::CE<3> cc;
  cc.pint();

  teaflow::CE<1> c2;
  c2.pint();
  
  teaflow::CE<1, 1> c3;
  c3.pint();
  return 0;
}

輸出結果:

1 2
0
1 1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章