Error code enums

Let’s replace err with something likely in many people’s code, a strongly typed enum:


  struct udt
  {
    int a{0};
    explicit udt(int _a)
        : a(_a)
    {
    }
    udt() = default;
    int operator*() const { return a; }
  };
  enum class err
  {
    success,   // 0 should not represent an error
    failure1,  // (for rationale, see tutorial on error codes)
    failure2
  };
  result<udt, err> res(err::failure1);

  // What happens here? What exception type is thrown?
  try
  {
    std::cout << *res.value() << std::endl;
  }
  catch(const std::exception &e)
  {
    std::cerr << "Exception thrown was " << e.what() << std::endl;
  }
  
View this code on Github