Skip to content

Commit

Permalink
Addition of ~ bitwise operator (#10)
Browse files Browse the repository at this point in the history
* Add ~ operator dispatch

* test for ~ operator
  • Loading branch information
wsphillips authored May 14, 2020
1 parent bf83d4e commit b3c926d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/operators.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: +, -, *, &, |, xor, ==
import Base: +, -, *, &, |, xor, ==, ~

for op in (:+, :-, :&, :|, :xor, :(==))
@eval begin
Expand All @@ -14,4 +14,8 @@ for op in (:+, :-, :&, :|, :xor, :(==))
end
end

function ~(a::Cenum{T}) where {T<:Integer}
~(T(a))
end

Base.convert(::Type{T1}, x::Cenum{T2}) where {T1<:Integer,T2<:Integer} = convert(T1, T2(x))
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Test
@test apple + 1 == 2
@test kiwi - 1 == 1
@test kiwi kiwi == 0
@test ~orange == -3
@test_nowarn print(devnull, Fruit(apple | orange))

@cenum(Boolean::Bool, alternativefact, fact)
Expand Down

0 comments on commit b3c926d

Please sign in to comment.