This commit is contained in:
Treb Connell 2015-09-28 15:17:37 -07:00
parent 27ff004e84
commit a46d6fcf0d
2 changed files with 53 additions and 31 deletions

View File

@ -223,12 +223,12 @@ public:
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>> 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.get()), tested_(false) {} maybe_null_dbg(const maybe_null_dbg<U> &other) : ptr_(other.ptr_), tested_(false) {}
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>> 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) maybe_null_dbg& operator=(const maybe_null_dbg<U> &other)
{ {
ptr_ = other.get(); ptr_ = other.ptr_;
tested_ = false; tested_ = false;
return *this; return *this;
} }

View File

@ -256,42 +256,64 @@ SUITE(MaybeNullTests)
CHECK(p1.get() != nullptr); CHECK(p1.get() != nullptr);
} }
TEST(TestMaybeNullAssignmentOps) template<class maybe_null_type>
{ void TestMaybeNullAssignmentOpsHelper()
MyBase base; {
MyDerived derived; MyBase base;
Unrelated unrelated; MyDerived derived;
Unrelated unrelated;
not_null<MyBase*> nnBase(&base); not_null<MyBase*> nnBase(&base);
not_null<MyDerived*> nnDerived(&derived); not_null<MyDerived*> nnDerived(&derived);
not_null<Unrelated*> nnUnrelated(&unrelated); not_null<Unrelated*> nnUnrelated(&unrelated);
maybe_null_ret<MyBase*> mnBase_ret1(&base), mnBase_ret2; maybe_null_type::type<MyBase*> mnBase_ret1(&base), mnBase_ret2;
mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T> mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T>
mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T> mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T>
maybe_null_ret<MyDerived*> mnDerived_ret(&derived); maybe_null_type::type<MyDerived*> mnDerived_ret(&derived);
mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U> mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U>
mnBase_ret1 = &derived; // maybe_null_ret<T> = U; mnBase_ret1 = &derived; // maybe_null_ret<T> = U;
mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U> mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U>
maybe_null_ret<Unrelated*> mnUnrelated_ret; maybe_null_type::type<Unrelated*> mnUnrelated_ret;
mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T
maybe_null_dbg<MyBase*> mnBase_dbg1(&base), mnBase_dbg2; maybe_null_type::type<MyBase*> mnBase_dbg1(&base), mnBase_dbg2;
mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T> mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T>
mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T> mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T>
maybe_null_dbg<MyDerived*> mnDerived_dbg(&derived); maybe_null_type::type<MyDerived*> mnDerived_dbg(&derived);
CHECK(mnDerived_dbg.present()); CHECK(mnDerived_dbg.present());
mnBase_dbg2 = mnDerived_dbg; // maybe_null_dbg<T> = maybe_null_dbg<U> 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>
maybe_null_dbg<Unrelated*> mnUnrelated_dbg; mnBase_dbg1 = &derived; // maybe_null_dbg<T> = U;
mnUnrelated_dbg = &unrelated; // maybe_null_dbg<T> = T 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>();
}
} }
int main(int, const char *[]) int main(int, const char *[])