Add option to skip forward to the generator interface

This commit is contained in:
Martin Hořeňovský
2025-10-06 11:47:38 +02:00
parent 363ca5af18
commit fecf606a05
22 changed files with 353 additions and 19 deletions

View File

@@ -39,6 +39,22 @@ public:
current_number = m_dist(m_rand);
return true;
}
// Note: this improves the performance only a bit, but it is here
// to show how you can override the skip functionality.
void skipToNthElementImpl( std::size_t n ) override {
auto current_index = currentElementIndex();
assert(current_index <= n);
// We cannot jump forward the underlying generator directly,
// because we do not know how many bits each distributed number
// would consume to be generated.
for (; current_index < n; ++current_index) {
(void)m_dist(m_rand);
}
// We do not have to touch the current element index; it is handled
// by the base class.
}
};
// Avoids -Wweak-vtables