Re: strong enums: why implicit conversion to basetype?

2012-01-29 Thread Marco Leise
Am 27.01.2012, 20:01 Uhr, schrieb Era Scarecrow rtcv...@yahoo.com: El 26/01/2012 14:59, Trass3r escribi?: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces

Re: strong enums: why implicit conversion to basetype?

2012-01-29 Thread bearophile
This is an important topic. I have an enhancement requests on enums: http://d.puremagic.com/issues/show_bug.cgi?id=3999 As usual language design is a matter of finding the right balance between strictness, that helps catch real bugs, and type sloppiness that makes code more handy, and avoids

Re: strong enums: why implicit conversion to basetype?

2012-01-29 Thread Era Scarecrow
///T of type ENUM, and S of an integral. struct HandleFlags(T, S)   {     S state;    ///Holds state.     alias T T_Enum;  this(T[] setFlags...);     ///Returns true/false if a specific ENUM flag has been set.     bool check(T[] flag...);     ///Returns true/false if

Re: strong enums: why implicit conversion to basetype?

2012-01-27 Thread Chad J
On 01/26/2012 08:17 PM, Simen Kjærås wrote: On Thu, 26 Jan 2012 23:49:40 +0100, Alvaro alvarodotseg...@gmail.com wrote: El 26/01/2012 14:59, Trass3r escribió: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit

Re: strong enums: why implicit conversion to basetype?

2012-01-27 Thread Don Clugston
On 26/01/12 21:26, Trass3r wrote: Is there any merit in having implicit conversion to the basetype? Allowing it to be used as an argument when calling C functions? extern(C): enum Bla : int {...} void foo(Bla b); How does this require implicit conversion? The codegen treats Bla like

Re: strong enums: why implicit conversion to basetype?

2012-01-27 Thread Trass3r
extern(C): enum Bla : int {...} void foo(Bla b); How does this require implicit conversion? The codegen treats Bla like basetype anyway. Some of the Windows functions are made of multiple enums of different types, ORed together. -.- Microsuckx. Then I think it should either become a

Re: strong enums: why implicit conversion to basetype?

2012-01-27 Thread Era Scarecrow
El 26/01/2012 14:59, Trass3r escribi?: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces a severe bug source and brings no advantages. Sometimes,

Re: strong enums: why implicit conversion to basetype?

2012-01-27 Thread Simen Kjærås
On Fri, 27 Jan 2012 13:34:06 +0100, Chad J chadjoan@__spam.is.bad__gmail.com wrote: On 01/26/2012 08:17 PM, Simen Kjærås wrote: On Thu, 26 Jan 2012 23:49:40 +0100, Alvaro alvarodotseg...@gmail.com wrote: El 26/01/2012 14:59, Trass3r escribió: I thought it'd be good to outsource this

strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces a severe bug source and brings no advantages. For example it allows implicit conversion to bool. enum Bla {

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Trass3r wrote: but by using named enums I made clear that Bla and Blub are totally different No. Obviously you decjlared both to be implicitely convertable to a common super type: int. To change this, both supertypes have be changed. The impßlementation is unfortenatey broken: void

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
On Thursday, 26 January 2012 at 14:45:02 UTC, Manfred Nowak wrote: Trass3r wrote: but by using named enums I made clear that Bla and Blub are totally different No. Obviously you decjlared both to be implicitely convertable to a common super type: int. To change this, both supertypes have

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Trass3r wrote: Is there any merit in having implicit conversion to the basetype? Yes. Otherwise it would be at least close to equivalence to a `typedef'. -manfred

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Trass3r wrote: That's why I question the implicit conversion. Yes. I realized my fault and canceled my message, but wasn't fast enough. -manfred

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
Is there any merit in having implicit conversion to the basetype? Yes. Otherwise it would be at least close to equivalence to a `typedef'. Even typedef implicitly converts in one of the directions. A named enum is a separate type with a finite set of allowed values defined by the user.

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Trass3r wrote: Even typedef implicitly converts in one of the directions. `typedef' is or will be disallowed in D because of reasons I do not understand. In C and C++ their existence introduce problems because they increase the amount of parsing passes. A named enum is a separate type

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Timon Gehr
On 01/26/2012 02:59 PM, Trass3r wrote: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces a severe bug source and brings no advantages. For example it allows

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread deadalnix
Le 26/01/2012 14:59, Trass3r a écrit : I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces a severe bug source and brings no advantages. For example it allows

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
I have argued for banning those operations on strong enums before, but some objected to it because they wanted to use strong enums as bit flags. Yep, that's what the other thread 'using enums for flags' is about. But implicit conversions seem wrong in any case.

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
`typedef' is or will be disallowed in D because of reasons I do not understand. It's ill-defined. There are 4 possible types of typedef: http://d.puremagic.com/issues/show_bug.cgi?id=5467 In C and C++ their existence introduce problems because they increase the amount of parsing passes.

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Don
On 26.01.2012 14:59, Trass3r wrote: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Allowing it to be used as an argument when calling C functions? Without it, how would you

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Trass3r
Is there any merit in having implicit conversion to the basetype? Allowing it to be used as an argument when calling C functions? extern(C): enum Bla : int {...} void foo(Bla b); How does this require implicit conversion? The codegen treats Bla like basetype anyway.

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Trass3r wrote: It's ill-defined. There are 4 possible types of typedef: http://d.puremagic.com/issues/show_bug.cgi?id=5467 [...] Again, this thread is all about discussing the right way to do it and not about what the buggy and holey spec reads. [...] I don't see any merit in that. You

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Alvaro
El 26/01/2012 14:59, Trass3r escribió: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only introduces a severe bug source and brings no advantages. A better example is

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Manfred Nowak
Alvaro wrote: With a non-int-convertible bool your above weird example would not work. But that the example works is not the fault of the existence of enums. It is due to the fact that omission, inclusion or change of one character can produce a different value without any warning.

Re: strong enums: why implicit conversion to basetype?

2012-01-26 Thread Simen Kjærås
On Thu, 26 Jan 2012 23:49:40 +0100, Alvaro alvarodotseg...@gmail.com wrote: El 26/01/2012 14:59, Trass3r escribió: I thought it'd be good to outsource this question from the other thread about enums as flags. Is there any merit in having implicit conversion to the basetype? Imo it only