-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarray.hpp
73 lines (62 loc) · 1.19 KB
/
carray.hpp
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
63
64
65
66
67
68
69
70
71
72
73
//
// Created by yanlei on 16-10-12.
//
#ifndef STL_CARRAY_HPP
#define STL_CARRAY_HPP
#include <cstddef>
template<class T, std::size_t thesize>
class carry
{
private:
T v[thesize]; //fixed-size array of elements of type T
public:
//type definitions
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
//iterator support
iterator begin()
{
return v;
}
const_iterator begin() const
{
return v;
}
iterator end()
{
return v+thesize;
}
const_iterator end() const
{
return v+thesize;
}
//direct elements access
reference operator[](std::size_t i)
{
return v[i];
}
const_reference operator[](std::size_t i) const
{
return v[i];
}
//size is constant
size_type size() const
{
return thesize;
}
size_type max_size() const
{
return thesize;
}
//conversion to ordinary array
T* as_array()
{
return v;
}
};
#endif //STL_CARRAY_HPP