Skip to content

Commit

Permalink
fixes missing raw pointer comparision in variants
Browse files Browse the repository at this point in the history
raw pointers are a comparable type. So it is added to the list of comparable types.
'is_comparable_type<T>::value'

Fixes #55
  • Loading branch information
acki-m committed May 7, 2017
1 parent 0e48f0b commit e4d729d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rttr/detail/comparison/comparable_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ using is_comparable_type = std::integral_constant<bool, std::is_same<T, std::str
std::is_same<T, string_view>::value ||
std::is_arithmetic<T>::value ||
std::is_enum<T>::value ||
std::is_same<T, std::nullptr_t>::value
std::is_same<T, std::nullptr_t>::value ||
std::is_pointer<T>::value
>;

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down
25 changes: 25 additions & 0 deletions src/unit_tests/variant/variant_cmp_equal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ TEST_CASE("variant::operator==() - template type - comparator registered", "[var
CHECK((a != a) == false);
}
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("variant::operator==() - nullptr type", "[variant]")
Expand Down Expand Up @@ -448,3 +449,27 @@ TEST_CASE("variant::operator==() - nullptr type", "[variant]")
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("variant::operator==() - pointer type", "[variant]")
{
SECTION("valid pointer compare")
{
int value = 23;
variant a = &value;
variant b = &value;

CHECK((a == b) == true);
}

SECTION("invalid pointer compare")
{
int value1 = 23;
int value2 = 42;
variant a = &value1;
variant b = &value2;

CHECK((a == b) == false);
}
}

/////////////////////////////////////////////////////////////////////////////////////////

0 comments on commit e4d729d

Please sign in to comment.