Skip to content

Commit 1c6693f

Browse files
committed
Make BitFlag values scalars in broadcasting
Duplicates improvement made to Base's Enums: JuliaLang/julia#30675
1 parent 74d13e3 commit 1c6693f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/BitFlags.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Base.isless(x::T, y::T) where {T<:BitFlag} = isless(basetype(T)(x), basetype(T)(
2525
Base.:|(x::T, y::T) where {T<:BitFlag} = T(Integer(x) | Integer(y))
2626
Base.:&(x::T, y::T) where {T<:BitFlag} = T(Integer(x) & Integer(y))
2727

28+
Base.broadcastable(x::BitFlag) = Ref(x)
29+
2830
function Base.print(io::IO, x::T) where T<:BitFlag
2931
compact = get(io, :compact, false)::Bool
3032
xi = Integer(x)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ end
6666
# Hashing
6767
@test Int(flag2a) == Int(flag3a) # same numerical value, but
6868
@test hash(flag2a) != hash(flag3a) # unique hashes as BitFlag
69+
70+
# Broadcasting
71+
@test [flag1a, flag1b] .| flag1c == [flag1a | flag1c, flag1b | flag1c]
6972
#end
7073

7174
#@testset "Type properties" begin

0 commit comments

Comments
 (0)