EllAlgo 1.6.13
Loading...
Searching...
No Matches
round_robin.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstddef>
9
19 public:
21 RoundRobin() : _lo{0}, _hi{0}, _cur{0} {}
22
24 explicit RoundRobin(std::size_t hi) : RoundRobin{0, hi} {}
25
27 RoundRobin(std::size_t lo, std::size_t hi) : _lo{lo}, _hi{hi}, _cur{hi - 1} {}
28
30 auto next() -> std::size_t {
31 if (++this->_cur == this->_hi) {
32 this->_cur = this->_lo;
33 }
34 return this->_cur;
35 }
36
37 private:
38 std::size_t _lo;
39 std::size_t _hi;
40 std::size_t _cur;
41};
Round-robin index generator over a half-open range [lo, hi)
Definition round_robin.hpp:18
RoundRobin(std::size_t lo, std::size_t hi)
Round-robin over [lo, hi)
Definition round_robin.hpp:27
auto next() -> std::size_t
Advance to the next index and return it.
Definition round_robin.hpp:30
RoundRobin()
Default-construct (uninitialized; reassign before use)
Definition round_robin.hpp:21
RoundRobin(std::size_t hi)
Round-robin over [0, hi)
Definition round_robin.hpp:24
auto invalid_value() -> T
Return an invalid/sentinel value for type T.
Definition cutting_plane.hpp:27