September 25, 2012
.NET has FlagsAttribute, Java has EnumSet. Looks like we need this too. How about to add a library solution to Phobos?

My variant is here (search for `flagEnum`):
https://bitbucket.org/denis_sh/misc/src/tip/stdd/typecons.d

It has a bug and I have no idea how to fix it:
`AB.init |= AB.a` and `AB.a |= AB.a` are allowed.
(no, we can't make `AB.a` const to disallow the second case because it will disallow this: `auto a = AB.a; a |= AB.a;`)

Also I'm not sure:
* Should we support converting from a number to a flag enum?
* If so, should we support values not from enum flags or throw exceptions (it may be configurable)?
* Is `flagEnum` an appropriate name?



-- 
Денис В. Шеломовский
Denis V. Shelomovskij
September 25, 2012
On Tuesday, 25 September 2012 at 17:13:44 UTC, Denis Shelomovskij wrote:
> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this too. How about to add a library solution to Phobos?

See also:
http://d.puremagic.com/issues/show_bug.cgi?id=6946

Bye,
bearophile
September 25, 2012
25.09.2012 22:03, bearophile пишет:
> On Tuesday, 25 September 2012 at 17:13:44 UTC, Denis Shelomovskij wrote:
>> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this
>> too. How about to add a library solution to Phobos?
>
> See also:
> http://d.puremagic.com/issues/show_bug.cgi?id=6946
>
> Bye,
> bearophile

Thanks, I was almost sure there is such issue. I added to the issue a link to this thread.

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
September 25, 2012
On 25/09/2012 20:03, bearophile wrote:
> On Tuesday, 25 September 2012 at 17:13:44 UTC, Denis Shelomovskij wrote:
>> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this
>> too. How about to add a library solution to Phobos?
>
> See also:
> http://d.puremagic.com/issues/show_bug.cgi?id=6946
>
> Bye,
> bearophile

comment on code:
Isn't there a way to retrieve all reserved words?

And, did you do a pull request?
September 25, 2012
Faux Amis:

> Isn't there a way to retrieve all reserved words?

I think the answer is negative.


> And, did you do a pull request?

I don't do those yet. And that code is just a prototype.

Bye,
bearophile
September 25, 2012
Faux Amis:

> Isn't there a way to retrieve all reserved words?

This is a possibility:

assert(__traits(is_reserved_word, "import"));

Bye,
bearophile
September 26, 2012
25.09.2012 21:14, Denis Shelomovskij пишет:
> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this too.
> How about to add a library solution to Phobos?
>
> My variant is here (search for `flagEnum`):
> https://bitbucket.org/denis_sh/misc/src/tip/stdd/typecons.d
>
> It has a bug and I have no idea how to fix it:
> `AB.init |= AB.a` and `AB.a |= AB.a` are allowed.
> (no, we can't make `AB.a` const to disallow the second case because it
> will disallow this: `auto a = AB.a; a |= AB.a;`)
>
> Also I'm not sure:
> * Should we support converting from a number to a flag enum?
> * If so, should we support values not from enum flags or throw
> exceptions (it may be configurable)?
> * Is `flagEnum` an appropriate name?
>
>
>

OK. Looks like such functionality isn't needed and I don't have to do a pull request. What about to close
http://d.puremagic.com/issues/show_bug.cgi?id=6946
with WONTFIX?

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
September 26, 2012
On 26-Sep-12 21:39, Denis Shelomovskij wrote:
> 25.09.2012 21:14, Denis Shelomovskij пишет:
>> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this too.
>> How about to add a library solution to Phobos?
>>
>> My variant is here (search for `flagEnum`):
>> https://bitbucket.org/denis_sh/misc/src/tip/stdd/typecons.d
>>
>> It has a bug and I have no idea how to fix it:
>> `AB.init |= AB.a` and `AB.a |= AB.a` are allowed.
>> (no, we can't make `AB.a` const to disallow the second case because it
>> will disallow this: `auto a = AB.a; a |= AB.a;`)
>>
>> Also I'm not sure:
>> * Should we support converting from a number to a flag enum?

I'd suggest an explicit way to do so. Like to!(flagEnum) or a standalone helpers.

>> * If so, should we support values not from enum flags or throw
>> exceptions (it may be configurable)?
If to! is used I guess throw exceptions if it doesn't fit.

>> * Is `flagEnum` an appropriate name?

Since it's a type (right?) I'd think EnumFlag, FlagSet or even Java's EnumSet. Generally I think I like words 'set' and/or 'flag' in the name.

> OK. Looks like such functionality isn't needed and I don't have to do a
> pull request. What about to close
> http://d.puremagic.com/issues/show_bug.cgi?id=6946
> with WONTFIX?
>
First, calm down. Second, I, for one, like it.
The place to go is most likely std.bitmanip or std.typecons. I haven't looked much at the actual code but the usage seems straightforward.

Another thought is to generalize it to something beyond 1-bit flags. How about packing various flags (set of 3-state flag, 4-state flag  etc.) in one fixed struct?


-- 
Dmitry Olshansky
September 26, 2012
26.09.2012 21:52, Dmitry Olshansky пишет:
> On 26-Sep-12 21:39, Denis Shelomovskij wrote:
>> 25.09.2012 21:14, Denis Shelomovskij пишет:
>>> .NET has FlagsAttribute, Java has EnumSet. Looks like we need this too.
>>> How about to add a library solution to Phobos?
>>>
>>> My variant is here (search for `flagEnum`):
>>> https://bitbucket.org/denis_sh/misc/src/tip/stdd/typecons.d
>>>
>>> It has a bug and I have no idea how to fix it:
>>> `AB.init |= AB.a` and `AB.a |= AB.a` are allowed.
>>> (no, we can't make `AB.a` const to disallow the second case because it
>>> will disallow this: `auto a = AB.a; a |= AB.a;`)
>>>
>>> Also I'm not sure:
>>> * Should we support converting from a number to a flag enum?
>
> I'd suggest an explicit way to do so. Like to!(flagEnum) or a standalone
> helpers.
>
>>> * If so, should we support values not from enum flags or throw
>>> exceptions (it may be configurable)?
> If to! is used I guess throw exceptions if it doesn't fit.
>
>>> * Is `flagEnum` an appropriate name?
>
> Since it's a type (right?) I'd think EnumFlag, FlagSet or even Java's
> EnumSet. Generally I think I like words 'set' and/or 'flag' in the name.
>
>> OK. Looks like such functionality isn't needed and I don't have to do a
>> pull request. What about to close
>> http://d.puremagic.com/issues/show_bug.cgi?id=6946
>> with WONTFIX?
>>
> First, calm down. Second, I, for one, like it.

Thanks for the answer, but still there are only few guys here interesting in it to be included in Phobos, so WONTFIX-ing the issue looks reasonable. I can just support this struct in my library for you.

> The place to go is most likely std.bitmanip or std.typecons. I haven't
> looked much at the actual code but the usage seems straightforward.
>
> Another thought is to generalize it to something beyond 1-bit flags. How
> about packing various flags (set of 3-state flag, 4-state flag  etc.) in
> one fixed struct?

Please give me usage examples (unittests), and I will implement the functionality. Now I don't understand what are n-state flags and what is the difference with std.bitmanip.bitfields.

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
September 26, 2012
On 26-Sep-12 22:17, Denis Shelomovskij wrote:
>
> Please give me usage examples (unittests), and I will implement the
> functionality. Now I don't understand what are n-state flags and what is
> the difference with std.bitmanip.bitfields.
>

Well thinking more of it, bitfields indeed will do for a fixed bunch of flags (if it supports enums).

What's missing is an analog of BitArray but for arbitrary integer enum type to pack them efficiently (depending on number of possible values). Though I guess the usage is somewhat niche.


-- 
Dmitry Olshansky
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home