forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_iterator.cpp
More file actions
62 lines (53 loc) · 1.84 KB
/
fast_iterator.cpp
File metadata and controls
62 lines (53 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "pch.h"
TEST_CASE("fast_iterator")
{
{
// Forward iteration.
auto v = winrt::single_threaded_vector<int>({ 1, 2, 3 });
std::vector<int> result;
std::copy(begin(v), end(v), std::back_inserter(result));
REQUIRE((result == std::vector{ 1, 2, 3 }));
}
{
// Reverse iteration.
auto v = winrt::single_threaded_vector<int>({ 1, 2, 3 });
std::vector<int> result;
std::copy(rbegin(v), rend(v), std::back_inserter(result));
REQUIRE((result == std::vector{ 3, 2, 1 }));
}
{
// Value-initialization.
auto v = winrt::single_threaded_vector<int>({ 9, 5, 4, 1, 1, 3 });
decltype(begin(v)) dummy;
decltype(begin(v)) dummy2;
// Must be able to default-construct the iterator,
// but the only thing you can do with it is compare
// with another one.
REQUIRE(dummy == dummy2);
}
{
// Read-only random access.
auto v = winrt::single_threaded_vector<int>({ 9, 5, 4, 1, 1, 3 });
REQUIRE(std::is_heap(begin(v), end(v)));
auto vbegin = begin(v);
auto value = *vbegin++;
REQUIRE(value == 9);
value = *--vbegin;
REQUIRE(value == 9);
REQUIRE(vbegin[2] == 4);
REQUIRE(vbegin + 2 > vbegin);
REQUIRE(2 + vbegin > vbegin);
REQUIRE(2 - (vbegin + 4) > vbegin);
REQUIRE(vbegin < vbegin + 2);
REQUIRE(vbegin + 2 - 2 == vbegin);
REQUIRE(static_cast<uint32_t>(end(v) - begin(v)) == v.Size());
REQUIRE((begin(v) + 3)[-1] == 4);
}
{
// ensure that importing std::begin and std::end does not break existing code
using std::begin;
using std::end;
auto v = winrt::single_threaded_vector<int>({ 9, 5, 4, 1, 1, 3 });
REQUIRE(std::is_heap(begin(v), end(v)));
}
}