std.conv: conversion from ulong to enum

Matej Nanut matejnanut at gmail.com
Thu Aug 22 15:48:53 PDT 2013


Hi everyone,

I hope I'm not misunderstanding the spec when this won't compile:

---
import std.conv;
enum Test { a = 0 }
void main() {
     ulong l = 0;
     auto t = l.to!Test;
}
---

It doesn't compile due to the template not instantiating.

If l is an int, uint or byte, it compiles fine.  I'm assuming the 
fault lies in the ‘is(S : OriginalType!T)’ constraint.

So, um, is this intended behaviour?  And why are string enums not 
supported? Wouldn't the ‘==’ operator work just fine on them too 
(so the function body would stay the same)?

Thanks,
Matej


More information about the Digitalmars-d mailing list