Skip to content

allow tagged_bool comparisons with normal bools #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/ak_toolkit/tagged_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class tagged_bool
constexpr tagged_bool operator!() const { return tagged_bool{!value}; }

friend constexpr bool operator==(tagged_bool l, tagged_bool r) { return l.value == r.value; }
friend constexpr bool operator==(tagged_bool l, bool r) { return l.value == r; }
friend constexpr bool operator==(bool l, tagged_bool r) { return l == r.value; }

friend constexpr bool operator!=(tagged_bool l, tagged_bool r) { return l.value != r.value; }
friend constexpr bool operator!=(tagged_bool l, bool r) { return l.value != r; }
friend constexpr bool operator!=(bool l, tagged_bool r) { return l != r.value; }
};

}
Expand Down
12 changes: 12 additions & 0 deletions test/test_explicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ void demonstrate_tagged_bool()
if (a) assert (true);
else assert (false);

if (a == true) assert(true);
else assert(false);

if (true == a) assert(true);
else assert(false);

if (a != false) assert(true);
else assert(false);

if (false != a) assert(true);
else assert(false);

constexpr BoolB ba {a};
assert (ba);
static_assert (ba && a, "failed tagged_bool");
Expand Down