]>
git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_src/begin_end.cpp
4 // const_iterator begin() const;
7 // const_iterator end() const;
10 #include <libkern/c++/bounded_array.h>
11 #include "test_policy.h"
12 #include <darwintest.h>
13 #include <type_traits>
21 // Check begin()/end() for a non-empty array
23 test_bounded_array
<T
, 5> array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
24 test_bounded_ptr
<T
> begin
= array
.begin();
25 test_bounded_ptr
<T
> end
= array
.end();
26 CHECK(begin
.discard_bounds() == array
.data());
27 CHECK(end
.unsafe_discard_bounds() == array
.data() + 5);
30 test_bounded_array
<T
, 5> const array
= {T
{0}, T
{1}, T
{2}, T
{3}, T
{4}};
31 test_bounded_ptr
<T
const> begin
= array
.begin();
32 test_bounded_ptr
<T
const> end
= array
.end();
33 CHECK(begin
.discard_bounds() == array
.data());
34 CHECK(end
.unsafe_discard_bounds() == array
.data() + 5);
37 // Check begin()/end() for an empty array
39 test_bounded_array
<T
, 0> array
= {};
40 test_bounded_ptr
<T
> begin
= array
.begin();
41 test_bounded_ptr
<T
> end
= array
.end();
42 CHECK(begin
.unsafe_discard_bounds() == array
.data());
43 CHECK(end
.unsafe_discard_bounds() == array
.data());
46 test_bounded_array
<T
, 0> const array
= {};
47 test_bounded_ptr
<T
const> begin
= array
.begin();
48 test_bounded_ptr
<T
const> end
= array
.end();
49 CHECK(begin
.unsafe_discard_bounds() == array
.data());
50 CHECK(end
.unsafe_discard_bounds() == array
.data());
53 // Check associated types
55 using A
= test_bounded_array
<T
, 10>;
56 static_assert(std::is_same_v
<typename
A::iterator
, test_bounded_ptr
<T
> >);
57 static_assert(std::is_same_v
<typename
A::const_iterator
, test_bounded_ptr
<T
const> >);
61 T_DECL(begin_end
, "bounded_array.begin_end") {