| 3741 | } |
| 3742 | |
| 3743 | bool next() override { |
| 3744 | // There are 2 basic cases: |
| 3745 | // 1) We are still reading the generator |
| 3746 | // 2) We are reading our own cache |
| 3747 | |
| 3748 | // In the first case, we need to poke the underlying generator. |
| 3749 | // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache |
| 3750 | if (m_current_repeat == 0) { |
| 3751 | const auto success = m_generator.next(); |
| 3752 | if (!success) { |
| 3753 | ++m_current_repeat; |
| 3754 | } |
| 3755 | return m_current_repeat < m_target_repeats; |
| 3756 | } |
| 3757 | |
| 3758 | // In the second case, we need to move indices forward and check that we haven't run up against the end |
| 3759 | ++m_repeat_index; |
| 3760 | if (m_repeat_index == m_returned.size()) { |
| 3761 | m_repeat_index = 0; |
| 3762 | ++m_current_repeat; |
| 3763 | } |
| 3764 | return m_current_repeat < m_target_repeats; |
| 3765 | } |
| 3766 | }; |
| 3767 | |
| 3768 | template <typename T> |