Provided Operation/Add/Multiply are supporting types. Prototype dispatches apply through const Operation&. Final Pipeline.add takes unique ownership of a nonnull operation; reject null with invalid_argument without adding. run applies operations in insertion order, starting from supplied value; empty pipeline returns it. Propagate operation exceptions. Destroy owned operations exactly once when the pipeline dies. Arithmetic test inputs fit Int. No copying of operations is required.

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. No runtime type coercion is required; C++ static types exclude many dynamic-language type errors. Unless a lesson states otherwise, string ordering is lexicographic over Unicode code points (Text) or UTF-8 identifiers (std::string).

cpp
struct Operation {virtual ~Operation()=default;virtual Int apply(Int value) const=0;};
struct Add final:Operation {Int delta;explicit Add(Int delta):delta(delta){} Int apply(Int value)const override{return value+delta;}};
struct Multiply final:Operation {Int factor;explicit Multiply(Int factor):factor(factor){} Int apply(Int value)const override{return value*factor;}};
inline Int prototype(const Operation& operation,Int value);
class Pipeline { public:
Pipeline();
void add(std::unique_ptr<Operation> operation);
Int run(Int value) const;
Int size() const;
};

Compile and run from this directory:

Shell
c++ -std=c++20 -O2 -Wall -Wextra -pedantic -pthread main.cpp -o practice
./practice --stage prototype
./practice --stage final

Edit exercise.hpp. Both stages start unfinished and must report failures until implemented. Keep main.cpp as the executable contract. The runner returns nonzero for a failed check, an unexpected exception, an invalid stage, or an empty suite. C++20 and only the standard library are required.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.

C++ runtime powered by Wasmer.