3 ms·
For those of us who don't know C++, would you care to provide a code sample (or a link to one) demonstrating what it would look like?
by lolinder 3y ago
For those of us who don't know C++, would you care to provide a code sample (or a link to one) demonstrating what it would look like?
- cjfd 3y ago#include <stdexcept> template <int min, int max> class Range { public: Range(int i): i(i) { if (i < min) throw std::runtime_error("value lower than minimum " + std::to_string(min)); if (i > max) throw std::runtime_error("value higher than maximum " + std::to_string(max)); } int to_int() const { return i; }; private: int i; }; using Month = Range<1, 12>; int main() { Month month(-1); } terminate called after throwing an instance of 'std::runtime_error' what(): value lower than minimum 1