折叠表达式
表格4.1列出所有可能的表达式:
1 #include <iostream> 2 #include <string> 3 4 template <typename ... Ts> 5 auto sum(Ts ... ts) { 6 return (... + ts); 7 } 8 9 int main() { 10 std::cout << sum(1, 2, 3, 4, 5) << std::endl;; //值为 5 11 12 std::string a {"Hello "}; 13 std::string b {"World"}; 14 std::string c {"!!!"}; 15 std::cout << sum(a, b, c) << std::endl; //值为 "Hello World!!!" 16 }