-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfixed_array.h
70 lines (55 loc) · 1.69 KB
/
fixed_array.h
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
#ifndef RDESTL_FIXED_ARRAY_H
#define RDESTL_FIXED_ARRAY_H
#include "algorithm.h"
namespace rde
{
//=============================================================================
template<typename T, size_t N>
class fixed_array
{
typedef char ERR_N_MustBeBiggerThanZero[N > 0 ? 1 : -1];
public:
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef size_t size_type;
T m_data[N];
// ctor, dtor, and assignment operator intentionally omitted
iterator begin() { return &m_data[0]; }
const_iterator begin() const { return &m_data[0]; }
iterator end() { return begin() + N; }
const_iterator end() const { return begin() + N; }
size_type size() const { return N; }
T* data() { return &m_data[0]; }
const T* data() const { return &m_data[0]; }
T& front() { return *begin(); }
const T& front() const { return *begin(); }
T& back() { return *(end() - 1); }
const T& back() const { return *(end() - 1); }
RDE_FORCEINLINE T& operator[](size_type i)
{
RDE_ASSERT(i < size());
return m_data[i];
}
RDE_FORCEINLINE const T& operator[](size_type i) const
{
RDE_ASSERT(i < size());
return m_data[i];
}
RDE_FORCEINLINE void fill(const T& value)
{
rde::fill_n(m_data, N, value);
}
RDE_FORCEINLINE void from_raw_array(const T arr[N])
{
rde::copy_n(&arr[0], N, data());
}
};
#if RDE_HAS_CPP11
// A condensed alias using standard container nomenclature
template<typename T, size_t N>
using array = fixed_array<T, N>;
#endif
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_FIXED_ARRAY_H