It’s a pity that there is no defined invalid value for size_t, which could be passed as default value. Would Rewind(std::optional<size_t> n = std::nullopt)
be a possibility here to unite the two methods? Like e.g.:
0diff --git a/src/streams.h b/src/streams.h
1index 2a921c2c5..a6e781b95 100644
2--- a/src/streams.h
3+++ b/src/streams.h
4@@ -14,6 +14,7 @@
5 #include <assert.h>
6 #include <ios>
7 #include <limits>
8+#include <optional>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <string.h>
12@@ -238,11 +239,6 @@ public:
13 ::SerializeMany(*this, std::forward<Args>(args)...);
14 }
15
16- void Rewind()
17- {
18- nReadPos = 0;
19- }
20-
21 std::string str() const
22 {
23 return (std::string(begin(), end()));
24@@ -339,12 +335,17 @@ public:
25 nReadPos = 0;
26 }
27
28- bool Rewind(size_type n)
29+ bool Rewind(std::optional<size_type> n = std::nullopt)
30 {
31+ // Total rewind if no size is passed
32+ if (!n) {
33+ nReadPos = 0;
34+ return true;
35+ }
36 // Rewind by n characters if the buffer hasn't been compacted yet
37- if (n > nReadPos)
38+ if (*n > nReadPos)
39 return false;
40- nReadPos -= n;
41+ nReadPos -= *n;
42 return true;
43 }
Probably overkill for methods that are only ever called in the benchmarks though…