# \[ANN\] New package FlagSets.jl - Manipulate flags bitwise or like sets

**URL:** https://discourse.julialang.org/t/ann-new-package-flagsets-jl-manipulate-flags-bitwise-or-like-sets/48717
**Category:** Package Announcements
**Tags:** package, announcement
**Created:** [October 20, 2020, 11:10pm UTC](https://discourse.julialang.org/t/ann-new-package-flagsets-jl-manipulate-flags-bitwise-or-like-sets/48717 "2020-10-20T23:10:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jessymilare](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jessymilare/32/13750_2.png) [@jessymilare](https://discourse.julialang.org/u/jessymilare)
#### Post date: [October 20, 2020, 11:10pm UTC](https://discourse.julialang.org/t/ann-new-package-flagsets-jl-manipulate-flags-bitwise-or-like-sets/48717/1 "2020-10-20T23:10:16Z")

</div>

[`FlagSets`](https://github.com/jessymilare/FlagSets.jl) is based on [`BitFlags.jl`](https://github.com/jmert/BitFlags.jl), but with a different concept: `FlagSet` is a subtype of `AbstractSet` and implement both set and bitwise operations (each bit is associated with a flag, and so a sequence of bits is associated with a set of flags - where 1 indicates the flag is in the set and 0 indicates it is not in the set).

I implemented this package mainly to create a higher level manipulation of flags from C libraries in Julia. I used to program in Common Lisp and the main interface for handling C libraries (CFFI) translates bit flags to lists of keywords (and vice-versa), which seems more like a high level library. Then I found the package `BitFlags`, which is nice, but doesn’t have tools for, e.g., getting the list of flags that are set in a `BitFlag`. Also, each flag is stored in a `const` variable, which is not bad, but looks like a low level language.

A few examples to illustrate the idea.

```julia
julia> @flagset FontFlags::UInt8 bold italic large=8

julia> FontFlags(1)
FontFlags(:bold) = 0x01

julia> FontFlags(:bold, :italic)
FontFlags(:bold, :italic) = 0x03

julia> FontFlags(3) | FontFlags(8)
FontFlags(:bold, :italic, :large) = 0x0b

julia> for flag in FontFlags(3); println(flag) end
bold
italic

julia> :bold in FontFlags(3)
true

```

Any suggestions, ideas or comments are welcome, of course.
