On Fri, 7 Feb 2020, 18:12 Михаил Найденов, <mihailnajdenov@gmail.com> wrote:


On Fri, Feb 7, 2020 at 7:08 PM Lee Howes <xrikcus@gmail.com> wrote:
Well the idea would be that you could unroll it too:
for co_await(auto [key, value] : dictionary) {
  foo(key, value);
}
(I forget what we intended for for co_await syntax, but it's not in there yet anyway so let's go with it)

The code would end up instantiating foo over all the key/value type combinations. The coroutine callback logic for dictionary iteration would yield each key/value pair by callback directly without any variant involved.

This is all speculation though, because actually implementing this and convincing people that the reader will not be confused is still a bit of a step.

This is template for, I believe

For the case of iterating over a static dictionary, template for would do well.

It doesn't, however, solve the issue of iterating over types yielded based on runtime values, such as a sequence of events generated by an input string. It would instead require the sequence of types to be known at compile time. A template for in this context would allow branching to different instantiation of the for block depending on the type generated on each iteration.