mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Adding derference operator to not_null (#513)
This commit is contained in:
parent
d1032864aa
commit
23581d4d63
@ -98,6 +98,7 @@ public:
|
||||
|
||||
constexpr operator T() const { return get(); }
|
||||
constexpr T operator->() const { return get(); }
|
||||
constexpr auto operator*() const { return *get(); }
|
||||
|
||||
// prevents compilation when someone attempts to assign a null pointer constant
|
||||
not_null(std::nullptr_t) = delete;
|
||||
|
@ -250,6 +250,21 @@ SUITE(NotNullTests)
|
||||
CHECK((NotNull1(p1) >= NotNull2(p2)) == (p1 >= p2));
|
||||
CHECK((NotNull2(p2) >= NotNull1(p1)) == (p2 >= p1));
|
||||
}
|
||||
|
||||
TEST(TestNotNullDereferenceOperator)
|
||||
{
|
||||
auto sp1 = std::make_shared<int>(42);
|
||||
|
||||
using NotNullSp1 = not_null<decltype(sp1)>;
|
||||
|
||||
CHECK(*NotNullSp1(sp1) == *sp1);
|
||||
|
||||
int ints[1] = {42};
|
||||
CustomPtr<int> p1(&ints[0]);
|
||||
|
||||
using NotNull1 = not_null<decltype(p1)>;
|
||||
CHECK(*NotNull1(p1) == 42);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, const char* []) { return UnitTest::RunAllTests(); }
|
||||
|
Loading…
Reference in New Issue
Block a user