File Storage System
Quota accounting and explicit expiration
Expiration affects lookup, search, and quota accounting together. Centralize deletion in advance_to so an expired entry releases bytes exactly once. Other operations observe the current logical time and do not read the wall clock.
struct File {std::string name;Int size;std::optional<Int> expires_at;};
// A copy preserves expires_at, not a new now+original_ttl deadline.Copying charges the full size again, even when metadata is small. Prepare source metadata before insertion and reject duplicate destinations before changing usage. Check available quota as size <= quota-used rather than computing an unchecked projected sum. Zero-byte files still own names and can expire. Value records keep returned metadata isolated. A linear expiration scan is O(N); adding an expiry heap is an optimization that must still handle stale records from deletion or name reuse.
C++ contract conventions: numeric values use signed Int (long long); all inputs and intermediate arithmetic are within its representable range. Opt<T> means std::optional<T> and absence is std::nullopt; Vec<T> means std::vector<T>. Invalid documented arguments throw std::invalid_argument. Inputs passed by const reference remain caller owned. Returned containers and records own their contents. Calls use the declared C++ parameter types. Implicit conversions performed by the caller are outside the runtime validation contract. Unless a lesson states otherwise, string ordering is lexicographic over Unicode code points (Text) or UTF-8 identifiers (std::string).
Put it into practice
Implement the exercise in a full-screen workspace, then run its tests.