Solutions
Use these to check your work after you’ve tried the exercises. If something differs, treat it as a debugging opportunity.
Exercise 1
Binding:
m.def("scale", &scale, py::arg("x"), py::arg("factor") = 1.0);
Exercise 2
std::pair<double,double> minmax(const std::vector<double>& v) {
auto [mn, mx] = std::minmax_element(v.begin(), v.end());
return {*mn, *mx};
}
Exercise 3
if (v.empty()) throw std::runtime_error("minmax: empty input");