Lambdas acting as coroutines/generators: [file = ifstream(path)]() mutable -> optional<string> { while (file.good()) { string line; getline(file, line); return line; // return next line } return {}; }; It's a bit of a trick, but works.https://godbolt.org/z/zj99dK
-
-
I'll be honest, I tend to stay away from while loops. Probably the graphics programmer in me liking bounded ranges. I think that's a blind spot for me in thinking about programming patterns. Enjoyed seeing this and shaking up my brain a bit!
-
I thought it was fun. Probably would have made a good lightning talk at a conference while you wait for the room to see what's going on. It's like a hand-wavy "look, I made a coroutine!" or something.
Keskustelun loppu
Uusi keskustelu -
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.