mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
commit
318cee0489
@ -178,6 +178,9 @@ class maybe_null_ret;
|
|||||||
template<class T>
|
template<class T>
|
||||||
class maybe_null_dbg
|
class maybe_null_dbg
|
||||||
{
|
{
|
||||||
|
template<class U>
|
||||||
|
friend class maybe_null_dbg;
|
||||||
|
|
||||||
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");
|
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");
|
||||||
public:
|
public:
|
||||||
maybe_null_dbg() : ptr_(nullptr), tested_(false) {}
|
maybe_null_dbg() : ptr_(nullptr), tested_(false) {}
|
||||||
@ -247,8 +250,10 @@ public:
|
|||||||
|
|
||||||
bool operator==(const T& rhs) const { tested_ = true; return ptr_ == rhs; }
|
bool operator==(const T& rhs) const { tested_ = true; return ptr_ == rhs; }
|
||||||
bool operator!=(const T& rhs) const { return !(*this == rhs); }
|
bool operator!=(const T& rhs) const { return !(*this == rhs); }
|
||||||
bool operator==(const maybe_null_dbg& rhs) const { tested_ = true; rhs.tested_ = true; return ptr_ == rhs.ptr_; }
|
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||||
bool operator!=(const maybe_null_dbg& rhs) const { return !(*this == rhs); }
|
bool operator==(const maybe_null_dbg<U>& rhs) const { tested_ = true; rhs.tested_ = true; return ptr_ == rhs.ptr_; }
|
||||||
|
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||||
|
bool operator!=(const maybe_null_dbg<U>& rhs) const { return !(*this == rhs); }
|
||||||
|
|
||||||
T get() const {
|
T get() const {
|
||||||
fail_fast_assert(tested_);
|
fail_fast_assert(tested_);
|
||||||
|
@ -178,6 +178,12 @@ SUITE(MaybeNullTests)
|
|||||||
maybe_null<MyBase*> q = p;
|
maybe_null<MyBase*> q = p;
|
||||||
CHECK(q == p);
|
CHECK(q == p);
|
||||||
|
|
||||||
|
maybe_null_dbg<MyDerived*> pdbg = &derived;
|
||||||
|
CHECK(pdbg.present());
|
||||||
|
|
||||||
|
maybe_null_dbg<MyBase*> qdbg = pdbg;
|
||||||
|
CHECK(qdbg == pdbg);
|
||||||
|
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
maybe_null<Unrelated*> r = p;
|
maybe_null<Unrelated*> r = p;
|
||||||
maybe_null<Unrelated*> s = reinterpret_cast<Unrelated*>(p);
|
maybe_null<Unrelated*> s = reinterpret_cast<Unrelated*>(p);
|
||||||
|
Loading…
Reference in New Issue
Block a user