#include <iostream>
#include <numeric>
#include <iterator>
#include <vector>
#include <functional>
template<typename Container>
std::string contents_as_string(Container const & c,
std::string const & separator) {
if (c.size() == 0) return "";
auto fold_operation = [&separator] (std::string const & accum,
auto const & item) {
return accum + separator + std::to_string(item);};
return std::accumulate(std::next(std::begin(c)), std::end(c),
std::to_string(*std::begin(c)), fold_operation);
}
int main() {
std::vector<double> v(4);
std::iota(std::begin(v), std::end(v), 0.1);
std::cout << contents_as_string(v, ", ") << std::endl;
std::vector<int> w(5);
std::iota(std::begin(w), std::end(w), 1);
std::cout << contents_as_string(w, " x ") << " = "
<< std::accumulate(std::begin(w), std::end(w), 1, std::multiplies<int>{})
<< std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCgp0ZW1wbGF0ZTx0eXBlbmFtZSBDb250YWluZXI+CnN0ZDo6c3RyaW5nIGNvbnRlbnRzX2FzX3N0cmluZyhDb250YWluZXIgY29uc3QgJiBjLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RkOjpzdHJpbmcgY29uc3QgJiBzZXBhcmF0b3IpIHsKICBpZiAoYy5zaXplKCkgPT0gMCkgcmV0dXJuICIiOwogIGF1dG8gZm9sZF9vcGVyYXRpb24gPSBbJnNlcGFyYXRvcl0gKHN0ZDo6c3RyaW5nIGNvbnN0ICYgYWNjdW0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYXV0byBjb25zdCAmIGl0ZW0pIHsKICAgIHJldHVybiBhY2N1bSArIHNlcGFyYXRvciArIHN0ZDo6dG9fc3RyaW5nKGl0ZW0pO307CiAgcmV0dXJuIHN0ZDo6YWNjdW11bGF0ZShzdGQ6Om5leHQoc3RkOjpiZWdpbihjKSksIHN0ZDo6ZW5kKGMpLAogICAgICAgICAgICAgICA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