|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
A replay attempt count, as a type distinct from a queue item id. More...
#include <offline_queue.hpp>
Public Member Functions | |
| constexpr | Attempts () noexcept=default |
| Constructs a zero attempt count. | |
| template<typename Count> requires (std::integral<Count> && !std::same_as<std::remove_cv_t<Count>, bool> && sizeof(Count) < sizeof(std::uint64_t)) | |
| constexpr | Attempts (Count count) noexcept |
| Implicitly wraps a narrow integral attempt count. | |
| constexpr std::uint32_t | value () const noexcept |
| Returns the wrapped count. | |
| constexpr bool | operator== (const Attempts &other) const noexcept=default |
| Compares two attempt counts. | |
A replay attempt count, as a type distinct from a queue item id.
setAttempts(itemId, attempts) takes two integers that mean entirely different things, and before this type existed both were plain unsigned integers, mutually convertible in either direction. Transposing them compiled, and — because setAttempts() on an unknown id is a documented no-op — it also ran: the real item's count never advanced, nothing threw, and the defect surfaced much later as a retry budget that never exhausts.
Attempts removes the hazard rather than suppressing the warning about it. It is implicitly constructible from a narrow integer, so setAttempts(id, 3) reads exactly as it did before, and deliberately not constructible from a 64-bit integer, which is what a QueueItem::id is — so the transposed call does not compile. A genuinely 64-bit count is still expressible, with the narrowing spelled out at the call site: setAttempts(id, static_cast<std::uint32_t>(count)).
Definition at line 41 of file offline_queue.hpp.
|
inlineconstexprnoexcept |
Implicitly wraps a narrow integral attempt count.
Constrained to integral types strictly narrower than a queue item id, which is the whole point of the class: uint64_t (and any other 64-bit integer) is rejected, so passing an item id where an attempt count belongs is a compile error rather than a silent no-op. bool is excluded because a boolean is never an attempt count.
| Count | Integral type of the incoming count. |
| count | The attempt count to wrap. |
Definition at line 59 of file offline_queue.hpp.
|
inlinenodiscardconstexprnoexcept |
Returns the wrapped count.
Definition at line 63 of file offline_queue.hpp.
|
nodiscardconstexprdefaultnoexcept |
Compares two attempt counts.
| other | The count to compare against. |