-
Notifications
You must be signed in to change notification settings - Fork 1
/
array.cpp
46 lines (30 loc) · 1.1 KB
/
array.cpp
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
#include <iostream>
#include "array.hpp"
int main()
{
ca::array<int, 3> ca;
*ca.end() = {}; // end() is not constant and is always dereferencable
ca.push_front(1ul);
ca.push_back(2ll, 3l); // push multiple values in one go
ca.push_front(4u);
std::sort(ca.begin(), ca.end());
std::cout << "size: " << ca.size() << std::endl;
std::cout << "full: " << ca.full() << std::endl;
std::copy(ca.cbegin(), ca.cend(), std::ostream_iterator<int>(std::cout, "\n"));
ca.push_back(5, 10);
std::cout << "size: " << ca.size() << std::endl;
std::cout << "full: " << ca.full() << std::endl;
for (auto&& [b, e]: ca.split())
std::copy(b, e, std::ostream_iterator<int>(std::cout, "\n"));
ca.erase(std::next(ca.cbegin()));
std::cout << "size: " << ca.size() << std::endl;
std::cout << "full: " << ca.full() << std::endl;
std::for_each(
ca.cbegin(),
ca.cend(),
[](auto&& v) { std::cout << v << std::endl; }
);
std::cout << std::distance(ca.cbegin(), ca.cend()) << " : " << ca.size() << " " << ca[0] << std::endl;
erase(ca, 10, 9, 8); // erase as much as you like
return 0;
}