Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/examples/300-Gen-OwnGenerator.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-10-06 11:47:38 +0200
committerMartin Hořeňovský2026-01-12 16:58:15 +0100
commit9eca713a1f4555b3095564781d77654958ee3dc1 (patch)
treee500e9b38c705f7f08ca412af16cb843cb80088e /examples/300-Gen-OwnGenerator.cpp
parent44c597f0742b491399994afa00070b99d3ef2885 (diff)
downloadcatch3-9eca713a1f4555b3095564781d77654958ee3dc1.tar.gz
Add option to skip forward to the generator interface
Diffstat (limited to 'examples/300-Gen-OwnGenerator.cpp')
-rw-r--r--examples/300-Gen-OwnGenerator.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/300-Gen-OwnGenerator.cpp b/examples/300-Gen-OwnGenerator.cpp
index 9cb02e39..b7f9d5da 100644
--- a/examples/300-Gen-OwnGenerator.cpp
+++ b/examples/300-Gen-OwnGenerator.cpp
@@ -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