2 ms·
Yeah, it's a real fold, just misleadingly named: int main() { string s[] = { "a", "b", "c" }; // will print "abc" cout << accumulate(s, s+3, stri
by hythloday 15y ago
Yeah, it's a real fold, just misleadingly named:
int main() {
string s[] = { "a", "b", "c" };
// will print "abc"
cout << accumulate(s, s+3, string(""), [](string l, string r) { return l+r; });
return 0;
}
I think a closer C++ equivalent for typeclasses are specialized template functions--for example, if I define:
template<InputIterator> string accumulate<string>(InputIterator first,
InputIterator last, string init);
then my call to accumulate(s, s+3, string("")) will use that specialization.