Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum bit masks #2988

Closed
wants to merge 2 commits into from
Closed

enum bit masks #2988

wants to merge 2 commits into from

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented May 1, 2013

This introduces a macro @enum_mask similar to @enum. However, rather than linear indexing, it uses powers of 2, and allows the standard c-style flag / mask manipulations.

julia> using Enum

julia> @enum_mask A b c d e

julia> A
enum mask A (b, c, d, e)

julia> b
A(b)

julia> b|c
A(b|c)

julia> ~d
A(b|c|e)

Thoughts? Is this the right approach? Should it be turned into a package now?

@StefanKarpinski
Copy link
Sponsor Member

I don't love the name, but the functionality is useful. I'm thinking we should spend some time and energy on the enum stuff and get the API right. That was just something I banged out one day.

@vtjnash vtjnash mentioned this pull request May 11, 2013
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jul 3, 2013

@JeffBezanson @StefanKarpinski Thoughts? OK to merge?

@ViralBShah
Copy link
Member

I would prefer to have this in base and with a better name.

$(esc(:(Base.start)))(x::Type{$(esc(T))}) = $(esc(:(Base.start)))($vals)
$(esc(:(Base.next)))(x::Type{$(esc(T))},s) = $(esc(:(Base.next)))($vals,s)
$(esc(:(Base.done)))(x::Type{$(esc(T))},s) = $(esc(:(Base.done)))($vals,s)
$(esc(:(Base.length)))(x::Type{$(esc(T))}) = $(length(vals))
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the enum type iterable seems very strange. Why not just provide a values(::Type{Enum}) function that provides a copy of the values array? Or maybe values should be stored as a tuple, which will be both immutable and iterable.

@jiahao
Copy link
Member

jiahao commented Oct 21, 2013

Tentatively marking as 0.2.x

@JeffBezanson
Copy link
Sponsor Member

This is a feature. Features are bad.

@staticfloat staticfloat mentioned this pull request Nov 19, 2013
21 tasks
adds additional syntax, functions, supertype, bugfixes to enums:
@enum X a b c=1 d=2
@enum_mask Y a b c d
@quinnj
Copy link
Member

quinnj commented Feb 21, 2015

The pure enum functionality here has been updated and merged in #10168, I guess the enum bitmask portion is still up for debate.

@quinnj
Copy link
Member

quinnj commented Apr 28, 2016

Should we close this? Do we really have a strong use-case for this in Base?

@quinnj quinnj closed this May 9, 2016
@tkelman tkelman deleted the jn/enum2 branch May 9, 2016 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants