std.conv: conversion from ulong to enum

2013-08-22 Thread Matej Nanut
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 as

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread Andrej Mitrovic
On 8/23/13, Matej Nanut wrote: > It doesn't compile due to the template not instantiating. It's likely a bug just like in Issue 6893[1], where this won't compile: - import std.stdio; enum E3 : ulong { A, B, C }; void main() { writeln(E3.C); } - [1] : http://d.puremagic.com/issues/

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread Andrei Alexandrescu
On 8/22/13 5:00 PM, Andrei Alexandrescu wrote: On 8/22/13 3:48 PM, Matej Nanut wrote: 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 t

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread Andrei Alexandrescu
On 8/22/13 3:48 PM, Matej Nanut wrote: 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 in

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread H. S. Teoh
On Thu, Aug 22, 2013 at 05:00:38PM -0700, Andrei Alexandrescu wrote: > On 8/22/13 5:00 PM, Andrei Alexandrescu wrote: > >On 8/22/13 3:48 PM, Matej Nanut wrote: > >>Hi everyone, > >> > >>I hope I'm not misunderstanding the spec when this won't compile: > >> > >>--- > >>import std.conv; > >>enum Test

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread Andrej Mitrovic
On 8/23/13, Andrej Mitrovic wrote: > to!() is used for save conversions I meant safe.

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread Andrej Mitrovic
On 8/23/13, H. S. Teoh wrote: > Whether to() *should* attempt the conversion > is a different matter, though. to!() is used for save conversions, so it should try to convert and throw an exception if conversion fails. For example: byte x = to!byte(int.max); std.conv.ConvOverflowException@conv.d

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread H. S. Teoh
On Fri, Aug 23, 2013 at 03:37:11AM +0200, Andrej Mitrovic wrote: > On 8/23/13, H. S. Teoh wrote: > > Whether to() *should* attempt the conversion > > is a different matter, though. > > to!() is used for save conversions, so it should try to convert and > throw an exception if conversion fails. Fo

Re: std.conv: conversion from ulong to enum

2013-08-22 Thread H. S. Teoh
On Thu, Aug 22, 2013 at 06:54:45PM -0700, H. S. Teoh wrote: > On Fri, Aug 23, 2013 at 03:37:11AM +0200, Andrej Mitrovic wrote: > > On 8/23/13, H. S. Teoh wrote: > > > Whether to() *should* attempt the conversion > > > is a different matter, though. > > > > to!() is used for save conversions, so i

Re: std.conv: conversion from ulong to enum

2013-08-23 Thread Matej Nanut
Well, that was fast! I'm glad it's fixed. :)