// // Tests for // iterator begin(); // const_iterator begin() const; // // iterator end(); // const_iterator end() const; // #include #include #include "test_utils.h" #include struct T { int i; }; template static void tests() { using A = test_safe_allocation; // Check begin()/end() for a non-null allocation { A array(10, libkern::allocate_memory); T* data = array.data(); test_bounded_ptr begin = array.begin(); test_bounded_ptr end = array.end(); CHECK(begin.discard_bounds() == data); CHECK(end.unsafe_discard_bounds() == data + 10); } { A const array(10, libkern::allocate_memory); T const* data = array.data(); test_bounded_ptr begin = array.begin(); test_bounded_ptr end = array.end(); CHECK(begin.discard_bounds() == data); CHECK(end.unsafe_discard_bounds() == data + 10); } // Check begin()/end() for a null allocation { A array = nullptr; test_bounded_ptr begin = array.begin(); test_bounded_ptr end = array.end(); CHECK(begin.unsafe_discard_bounds() == nullptr); CHECK(end.unsafe_discard_bounds() == nullptr); CHECK(begin == end); } { A const array = nullptr; test_bounded_ptr begin = array.begin(); test_bounded_ptr end = array.end(); CHECK(begin.unsafe_discard_bounds() == nullptr); CHECK(end.unsafe_discard_bounds() == nullptr); CHECK(begin == end); } // Check associated types { static_assert(std::is_same_v >); static_assert(std::is_same_v >); } } T_DECL(begin_end, "safe_allocation.begin_end", T_META_TAG_VM_PREFERRED) { tests(); tests(); }