For non-holy enums you can always do something like this:
    
    
    type X = enum
      Z
    
    template toEnum[T](x: int): T =
      if x in T.low.int..T.high.int:
        T(x)
      else:
        raise newException(ValueError, "Value not convertible to enum")
    
    var a = 42
    echo toEnum[X](a)
    
    
    Run

To be honest a `isValidFor` function that takes an enum type would be nice to 
have in the stdlib.

Reply via email to