Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


   #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




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: