17 March 2022

double sqrt(double x);


double sqrt(double x); // x 须为非负


#include <gsl/gsl_assert>
double sqrt(double x) { Expects(x >= 0); /* ... */ }
int main()
{
sqrt(-1.0);
return 0;
}

terminate called without an active exception


// the sequence [p:q) is ordered using <.
// 序列 [p:q) 以 < 排序


Most member functions have as a precondition that some class invariant holds. That invariant is established by a constructor and must be reestablished upon exit by every member function called from outside the class. We don’t need to mention it for each member function.