https://github.com/D-Programming-Language/dmd/pull/673
"Tommi" wrote in message
news:ozvdphftlwxkeumrn...@forum.dlang.org...
> On Monday, 15 October 2012 at 08:25:18 UTC, Tommi wrote:
>> in reality, it's very easy to write a bug that makes an enum variable
>> have an invalid value. E.g:
>
> Wri
On Monday, 15 October 2012 at 08:25:18 UTC, Tommi wrote:
in reality, it's very easy to write a bug that makes an enum
variable have an invalid value. E.g:
Writing that bug wasn't as easy as I thought though. Here's the
code with a bug:
enum MyEnum { first, second, third }
auto me = MyEnum.m
On Sunday, 14 October 2012 at 19:40:17 UTC, Nick Sabalausky wrote:
Yes, but it still has to be taken into account in things like
"final switch". You can't just pretend that nothing will ever
have that value, because by making it the init value, you've
*made* it an actual possible value, one that
On Sun, 14 Oct 2012 09:16:28 +0200
"Tommi" wrote:
> On Sunday, 14 October 2012 at 06:51:48 UTC, Jonathan M Davis
> wrote:
> > And honestly, declaring a specific init value for an enum is a
> > stupid idea.
>
> I think that declaring a specific *valid* init value for an enum
> has no purpose.
On Sunday, 14 October 2012 at 06:51:48 UTC, Jonathan M Davis
wrote:
And honestly, declaring a specific init value for an enum is a
stupid idea.
I think that declaring a specific *valid* init value for an enum
has no purpose. But declaring a specific *invalid* init value, to
which the enum ini
On Sunday, October 14, 2012 08:20:40 Tommi wrote:
> There's a bug in that code, because MyEnum default-initializes to
> an invalid value. It's effectively the same as this following
> code, where the programmer has failed to initialize MyEnum
> variable with a valid value:
Valid or not, MyEnum.ini
On Saturday, 13 October 2012 at 20:25:56 UTC, Jonathan M Davis
wrote:
MyEnum me;
final switch (me) // no init case necessary nor allowed
{
case MyEnum.first: break;
case MyEnum.second: break;
}
}
Think about that for a moment. What happens when that final
switc
On Saturday, October 13, 2012 17:39:23 Tommi wrote:
> I'd like to be able to specify a default value for a named enum,
> E.init, without creating a new enumeration. There are three
> reasons:
> 1) Default initializing enum variables to an "invalid" value
> 2) Being able to use 'final switch' withou
On 10/13/2012 11:01 AM, bearophile wrote:
denizzzka:
Why in case its need to write name of the enum?
Because D enums have a very simple design. But with() helps.
For me, that is the only benefit of 'with':
final switch (me) with (MyEnum)
{
case first: break;
case second: b
denizzzka:
Why in case its need to write name of the enum?
Because D enums have a very simple design. But with() helps.
Bye,
bearophile
On Saturday, 13 October 2012 at 15:39:24 UTC, Tommi wrote:
enum MyEnum
{
init = -123,
first = 0,
second = 1
}
void main()
{
static assert(MyEnum.min == -123);
MyEnum me;
final switch (me)
{
case MyEnum.first: break;
case MyEnum.second: break;
case MyEnu
11 matches
Mail list logo