Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: