使用
#include2 分支代码#include template struct fun { using RemRef = typename std::remove_reference ::type; using type = typename std::add_const ::type; }; int main() { fun ::type x=3; }
两种方法编写分支代码
#include#include constexpr int fun(int x) { if(x>3) return x*2; else return x-100; } template int fun() { if constexpr (x>3) return x*2; else return x-100; } int main() { constexpr int x = fun(100); int y = fun<100>(); }



