Continue from step 9 with a proposed insertion of . A rejecting operation
try_enqueue(H) returns full, writes nothing and leaves with . The next dequeue() returns , leaving with . Rejection requires the caller to decide whether to retry or abandon .An overwriting operation
append_latest(H) instead writes , advances , and keeps . It can report the discarded label as part of its specified result. At step 10 this gives with . The next dequeue() returns , leaving with . Below full capacity, append_latest follows the ordinary insertion rule without discarding anything.The lower bars in the trace diagram expose the consequence: entered at step 4 and remains a member until step 11 under rejection, but only until step 10 under overwrite. never becomes a member in the rejecting branch; it does in the overwriting branch. The same physical slot can therefore hold different logical items over time. These interfaces are observably different, so representation independence cannot justify exchanging them while retaining the same promised results.
Boost's documented
push_back behavior chooses overwrite when full, implemented by assignment to the old element. Its discussion of iterator invalidation illustrates why a reused address need not still identify the original item. Assignment, object destruction, and release of an owned resource are separate language-level concerns; the membership bars make no claim about those lifetimes.[ref]Implementation. Jan Gaspar, Boost.Circular Buffer, Implementation: Overwrite Operation; Writing to a Full Buffer; Iterator Invalidation; Caveats
A rejecting FIFO queue suits work that must remain pending until explicitly removed. An overwriting circular buffer suits a bounded recent history where losing the oldest retained item is the stated policy. Neither storage wrap nor bounded capacity chooses between those requirements.
Articles by others on the same topic
There are currently no matching articles.