Skip to content

Commit

Permalink
Make BitFlag values scalars in broadcasting
Browse files Browse the repository at this point in the history
Duplicates improvement made to Base's Enums: JuliaLang/julia#30675
  • Loading branch information
jmert committed Nov 10, 2022
1 parent 74d13e3 commit 6190b1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BitFlags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Base.isless(x::T, y::T) where {T<:BitFlag} = isless(basetype(T)(x), basetype(T)(
Base.:|(x::T, y::T) where {T<:BitFlag} = T(Integer(x) | Integer(y))
Base.:&(x::T, y::T) where {T<:BitFlag} = T(Integer(x) & Integer(y))

Base.broadcastable(x::BitFlag) = Ref(x)

function Base.print(io::IO, x::T) where T<:BitFlag
compact = get(io, :compact, false)::Bool
xi = Integer(x)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ end
# Hashing
@test Int(flag2a) == Int(flag3a) # same numerical value, but
@test hash(flag2a) != hash(flag3a) # unique hashes as BitFlag

# Broadcasting
@test [flag1a, flag1b] .| flag1c == [flag1a | flag1c, flag1b | flag1c]
#end

#@testset "Type properties" begin
Expand Down

0 comments on commit 6190b1f

Please sign in to comment.