yo/coroutines/demo/readbinary/floats/coread.cc
raw| 1 | #include "floats.ih" |
| 2 | |
| 3 | // this is the coroutine reading binary floats |
| 4 | |
| 5 | //read |
| 6 | Reader Floats::coRead() const |
| 7 | { |
| 8 | ifstream in{ d_filename }; |
| 9 | |
| 10 | while (true) |
| 11 | { |
| 12 | float value; |
| 13 | in.read(reinterpret_cast<char *>(&value), sizeof(float)); |
| 14 | |
| 15 | if (not in) |
| 16 | co_return; // if not: end the coroutine |
| 17 | |
| 18 | co_yield value; |
| 19 | } |
| 20 | } |
| 21 | //= |