From 94f991f03a094cc3e0b4ef8eba5f25d5265716bd Mon Sep 17 00:00:00 2001 From: Wiktor Phillips Date: Thu, 14 May 2020 10:55:00 +0200 Subject: [PATCH 1/2] Add ~ operator dispatch --- src/operators.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/operators.jl b/src/operators.jl index 87f8f13..d3b8245 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -1,4 +1,4 @@ -import Base: +, -, *, &, |, xor, == +import Base: +, -, *, &, |, xor, ==, ~ for op in (:+, :-, :&, :|, :xor, :(==)) @eval begin @@ -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)) From 0a9f8f9a91e5cdbe2b1a36dd7e6f44dceb45fd2a Mon Sep 17 00:00:00 2001 From: Wiktor Phillips Date: Thu, 14 May 2020 10:55:45 +0200 Subject: [PATCH 2/2] test for ~ operator --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 74e249d..5fe4c34 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)