Add forEach and ostream support.
Adapted Solution.