mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
parent
a46d6fcf0d
commit
b29566628e
@ -223,12 +223,12 @@ public:
|
||||
|
||||
|
||||
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||
maybe_null_dbg(const maybe_null_dbg<U> &other) : ptr_(other.ptr_), tested_(false) {}
|
||||
maybe_null_dbg(const maybe_null_dbg<U> &other) : ptr_(other.get()), tested_(false) {}
|
||||
|
||||
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||
maybe_null_dbg& operator=(const maybe_null_dbg<U> &other)
|
||||
{
|
||||
ptr_ = other.ptr_;
|
||||
ptr_ = other.get();
|
||||
tested_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
@ -256,64 +256,42 @@ SUITE(MaybeNullTests)
|
||||
CHECK(p1.get() != nullptr);
|
||||
}
|
||||
|
||||
template<class maybe_null_type>
|
||||
void TestMaybeNullAssignmentOpsHelper()
|
||||
{
|
||||
MyBase base;
|
||||
MyDerived derived;
|
||||
Unrelated unrelated;
|
||||
TEST(TestMaybeNullAssignmentOps)
|
||||
{
|
||||
MyBase base;
|
||||
MyDerived derived;
|
||||
Unrelated unrelated;
|
||||
|
||||
not_null<MyBase*> nnBase(&base);
|
||||
not_null<MyDerived*> nnDerived(&derived);
|
||||
not_null<Unrelated*> nnUnrelated(&unrelated);
|
||||
not_null<MyBase*> nnBase(&base);
|
||||
not_null<MyDerived*> nnDerived(&derived);
|
||||
not_null<Unrelated*> nnUnrelated(&unrelated);
|
||||
|
||||
maybe_null_type::type<MyBase*> mnBase_ret1(&base), mnBase_ret2;
|
||||
mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T>
|
||||
mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T>
|
||||
maybe_null_ret<MyBase*> mnBase_ret1(&base), mnBase_ret2;
|
||||
mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T>
|
||||
mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T>
|
||||
|
||||
maybe_null_type::type<MyDerived*> mnDerived_ret(&derived);
|
||||
mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U>
|
||||
mnBase_ret1 = &derived; // maybe_null_ret<T> = U;
|
||||
mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U>
|
||||
maybe_null_ret<MyDerived*> mnDerived_ret(&derived);
|
||||
mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U>
|
||||
mnBase_ret1 = &derived; // maybe_null_ret<T> = U;
|
||||
mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U>
|
||||
|
||||
maybe_null_type::type<Unrelated*> mnUnrelated_ret;
|
||||
mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T
|
||||
maybe_null_ret<Unrelated*> mnUnrelated_ret;
|
||||
mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T
|
||||
|
||||
maybe_null_type::type<MyBase*> mnBase_dbg1(&base), mnBase_dbg2;
|
||||
mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T>
|
||||
mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T>
|
||||
maybe_null_dbg<MyBase*> mnBase_dbg1(&base), mnBase_dbg2;
|
||||
mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T>
|
||||
mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T>
|
||||
|
||||
maybe_null_type::type<MyDerived*> mnDerived_dbg(&derived);
|
||||
CHECK(mnDerived_dbg.present());
|
||||
mnBase_dbg2 = mnDerived_dbg; // maybe_null_dbg<T> = maybe_null_dbg<U>
|
||||
maybe_null_dbg<MyDerived*> mnDerived_dbg(&derived);
|
||||
CHECK(mnDerived_dbg.present());
|
||||
mnBase_dbg2 = mnDerived_dbg; // maybe_null_dbg<T> = maybe_null_dbg<U>
|
||||
|
||||
mnBase_dbg1 = &derived; // maybe_null_dbg<T> = U;
|
||||
mnBase_dbg1 = nnDerived; // maybe_null_dbg<T> = not_null<U>
|
||||
mnBase_dbg1 = &derived; // maybe_null_dbg<T> = U;
|
||||
mnBase_dbg1 = nnDerived; // maybe_null_dbg<T> = not_null<U>
|
||||
|
||||
maybe_null_type::type<Unrelated*> mnUnrelated_dbg;
|
||||
mnUnrelated_dbg = &unrelated; // maybe_null_dbg<T> = T
|
||||
}
|
||||
|
||||
struct maybe_null_ret_type
|
||||
{
|
||||
template<typename T>
|
||||
using type = maybe_null_ret<T>;
|
||||
};
|
||||
struct maybe_null_dbg_type
|
||||
{
|
||||
template<typename T>
|
||||
using type = maybe_null_dbg<T>;
|
||||
};
|
||||
|
||||
TEST(TestMaybeNullRetAssignmentOps)
|
||||
{
|
||||
TestMaybeNullAssignmentOpsHelper<maybe_null_ret_type>();
|
||||
}
|
||||
|
||||
TEST(TestMaybeNullDbgAssignmentOps)
|
||||
{
|
||||
TestMaybeNullAssignmentOpsHelper<maybe_null_dbg_type>();
|
||||
}
|
||||
maybe_null_dbg<Unrelated*> mnUnrelated_dbg;
|
||||
mnUnrelated_dbg = &unrelated; // maybe_null_dbg<T> = T
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, const char *[])
|
||||
|
Loading…
Reference in New Issue
Block a user