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

To some extent, this seems like it's just a symptom of "writing iterators in C++ is harder than it ought to be". You don't need to have a tree in memory to build an iterator over it - folks write iterators over implicit data all the time.

Here's the range based for loop counterexample from the blog post, as a python generator:

  import itertools

  def iterate_tree():
      for length in range(1, 8):
          for combo in itertools.product("abc", repeat=length):
              yield ''.join(combo)

  for s in iterate_tree():
      print(s)


C++ also has generators[1], but the author is perhaps unaware of them.

[1] https://en.cppreference.com/w/cpp/coroutine/generator


"yield from" is also very useful to iterate trees in python.




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

Search: