C++通用print

Ref: https://zhuanlan.zhihu.com/p/338785886

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void println() {}
void println(auto x, auto... args)
{
std::cout << std::boolalpha;
std::cout << x << " ";
println(args...);
std::cout << std::endl;
}

// constexpr c++17 auto c++20
void print(auto firstArg, auto... args)
{
std::cout << firstArg << ' ';
if constexpr (sizeof...(args) > 0)
print(args...);
else
std::cout << std::endl;
}

C++可变参数模板的展开方式

https://blog.csdn.net/albertsh/article/details/123978539