Skip to content

Commit b3c926d

Browse files
authored
Addition of ~ bitwise operator (#10)
* Add ~ operator dispatch * test for ~ operator
1 parent bf83d4e commit b3c926d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/operators.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Base: +, -, *, &, |, xor, ==
1+
import Base: +, -, *, &, |, xor, ==, ~
22

33
for op in (:+, :-, :&, :|, :xor, :(==))
44
@eval begin
@@ -14,4 +14,8 @@ for op in (:+, :-, :&, :|, :xor, :(==))
1414
end
1515
end
1616

17+
function ~(a::Cenum{T}) where {T<:Integer}
18+
~(T(a))
19+
end
20+
1721
Base.convert(::Type{T1}, x::Cenum{T2}) where {T1<:Integer,T2<:Integer} = convert(T1, T2(x))

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using Test
1212
@test apple + 1 == 2
1313
@test kiwi - 1 == 1
1414
@test kiwi kiwi == 0
15+
@test ~orange == -3
1516
@test_nowarn print(devnull, Fruit(apple | orange))
1617

1718
@cenum(Boolean::Bool, alternativefact, fact)

0 commit comments

Comments
 (0)