常用的模板函数(持续更新)

输出多组数据

debug的时候用

//两种写法

// 递归写法.
template <typename T, typename ... U>
void Print(T t, U... u) {
    
    if constexpr(sizeof ...(U) == 0) {
        cout << t << endl;
    } else {
        cout << t << ", ";
        Print(u...); 
    }
}

// 逗号表达式写法
template<typename ...U>
void println(U...u) {
    int last_index = sizeof...(u) - 1, i = 0;
    ((i ++ < last_index ? (cout << u << ", ") : (cout << u << "\n")), ...);
}
posted @ 2021-09-12 17:09  ccz9729  阅读(48)  评论(0)    收藏  举报