C++ object lifetime: copies, moves and the rule of five

R-LIFETIME-V4-2medium

Move instead of copying

An upload queue reads add, retry and replace commands from stdin. Each upload owns one storage slot; the report lists the queue, counts slot copies and shows how many slots are still open after shutdown. Storage is an authored integer-slot model, not file/network I/O: copy rejects byte counts over 1000. Easy inputs use 0–1000-byte files because its copy-only growth may otherwise reject an add while relocating old elements; Medium/Hard allow 0–1000000 bytes: Medium requires the learner to add safe move support, which Hard already supplies. Inputs are well-formed complete commands, nonempty token names, valid indices, up to 100 queued uploads and distinct target/source indices for graded replace commands. Self-assignment remains a separate ungraded diagnostic because legal implementations can make different copy counts. Host allocation failure in std::string/map/vector, arbitrary moved-from describe calls and malformed input are outside the reported profile. The Hard target guarantee covers its name and slot contents on modeled copy rejection.

What needs to change

Change Upload so the queue moves uploads when it grows instead of copying them.

Reproduce

  1. Run the sample with two retries and compare the slot copies line with the expected stdout.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

Upload now has a copy constructor that duplicates the slot. The vector reallocates as uploads are added; slot copies counts calls to storage::copy.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in