A resource managed by std::unique_ptr must have exactly one owner at any moment.
In this problem, ownership of a dynamically allocated buffer must be explicitly transferred from one std::unique_ptr to another. The provided template code attempts to create a second owner for the same resource, which violates std::unique_ptr ownership rules and causes a compilation error.
Your task is to restructure the ownership flow so that the resource always has a single owner, the program compiles successfully, and the runtime behavior matches the expected output.
This problem emphasizes ownership semantics and lifetime control, not syntax tricks.
Program Flow:
NN using std::unique_ptrN integer values into the bufferstd::unique_ptr
Example Input:
4
10 20 30 40
Example Output:
10 20 30 40
No data
Constraints:
N ranges from 1 to 100uint8_t
Input
4 10 20 30 40
Expected Output
10 20 30 40 No data