|
LdsGen 1.2.6
|
CRTP base implementing the sequence generator protocol. More...
#include <lds.hpp>
Public Member Functions | |
| auto | pop () -> Value |
| Generate the next value in the sequence (advances state). | |
| auto | peek () -> Value |
| Peek at the next value without advancing state. | |
| auto | skip (unsigned int n) -> void |
| Skip n values in the sequence. | |
| auto | reseed (const unsigned long &seed) -> void |
| Reset the generator to a specific seed value. | |
| auto | get_index () const -> unsigned long |
| Get current index in the sequence. | |
Protected Attributes | |
| std::atomic< unsigned long > | count_ {0} |
| Current sequence index (single source of state) | |
Friends | |
| template<typename , typename > | |
| class | GeneratorIterable |
CRTP base implementing the sequence generator protocol.
Implements the shared stateful protocol (pop/peek/skip/reseed/get_index) in terms of a single pure computation value_at(n) supplied by the derived class. The sequence counter is a std::atomic<unsigned long> so the protocol stays thread-safe: pop() claims a unique index with a relaxed fetch_add and evaluates value_at on immutable generator data.
pop() evaluates value_at(fetch_add(1) + 1) and peek() evaluates value_at(load() + 1) — while the derived class supplies only the pure index-to-value computation. This guarantees pop/peek consistency by construction, centralizes the sequence state in one atomic counter (making composite pop() atomic as a point), and removes the duplicated protocol from every concrete generator.| Derived | The CRTP-derived generator class. |
| Value | The value type produced by pop()/peek(). |
|
inline |
Get current index in the sequence.
|
inline |
Peek at the next value without advancing state.
|
inline |
Generate the next value in the sequence (advances state).
Atomically claims the next index and evaluates the pure value_at computation.
|
inline |
Reset the generator to a specific seed value.
| [in] | seed | the seed value to reset the sequence generator to |
|
inline |
Skip n values in the sequence.
| [in] | n | number of values to skip |
|
friend |
|
protected |
Current sequence index (single source of state)