From b3c926de43cc1e1b72b684e9e031a08d5c9780d4 Mon Sep 17 00:00:00 2001 From: Wiktor Phillips Date: Thu, 14 May 2020 15:18:01 +0200 Subject: [PATCH] Addition of ~ bitwise operator (#10) * Add ~ operator dispatch * test for ~ operator --- src/operators.jl | 6 +++++- test/runtests.jl | 1 + 2 files changed, 6 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)) 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)