//main.cpp
#include <iostream>
#include <type_traits>
#include <numeric>
template<typename ... T>
void print(const T& ... args)
{
(void)std::initializer_list<int>{ (std::cout << args << ' ', 0)... };
std::cout << '\n';
}
template<typename ... T>
auto sum(const T& ... args)
{
using T_t = std::common_type_t<T...>;
auto arg_list = {args...};
return std::accumulate(std::begin(arg_list), std::end(arg_list), 0, std::plus<T_t>());
}
int main()
{
print("1", 2, 3.3f);
print(sum(1, 2, 3));
}
//output
1 2 3.3
6
网友评论