| 4115 | } |
| 4116 | |
| 4117 | bool next() override { |
| 4118 | // There are 2 basic cases: |
| 4119 | // 1) We are still reading the generator |
| 4120 | // 2) We are reading our own cache |
| 4121 | |
| 4122 | // In the first case, we need to poke the underlying generator. |
| 4123 | // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache |
| 4124 | if (m_current_repeat == 0) { |
| 4125 | const auto success = m_generator.next(); |
| 4126 | if (!success) { |
| 4127 | ++m_current_repeat; |
| 4128 | } |
| 4129 | return m_current_repeat < m_target_repeats; |
| 4130 | } |
| 4131 | |
| 4132 | // In the second case, we need to move indices forward and check that we haven't run up against the end |
| 4133 | ++m_repeat_index; |
| 4134 | if (m_repeat_index == m_returned.size()) { |
| 4135 | m_repeat_index = 0; |
| 4136 | ++m_current_repeat; |
| 4137 | } |
| 4138 | return m_current_repeat < m_target_repeats; |
| 4139 | } |
| 4140 | }; |
| 4141 | |
| 4142 | template <typename T> |