yo/coroutines/demo/readbinary/floats/cowrite.cc
raw| 1 | #include "floats.ih" |
| 2 | |
| 3 | // this is the coroutine writing binary floats |
| 4 | |
| 5 | // static |
| 6 | //write |
| 7 | Writer Floats::coWrite() |
| 8 | { |
| 9 | while (true) |
| 10 | { |
| 11 | float value; |
| 12 | if (not (cin >> value)) // get the next value |
| 13 | co_return; // if not: end the coroutine |
| 14 | |
| 15 | |
| 16 | Writer::ValueType ret; // value to return |
| 17 | |
| 18 | ret = Writer::ValueType{ string{ |
| 19 | reinterpret_cast<char const *>(&value), |
| 20 | reinterpret_cast<char const *>(&value + 1) } |
| 21 | }; |
| 22 | |
| 23 | co_yield ret; |
| 24 | } |
| 25 | } |
| 26 | //= |