summaryrefslogtreecommitdiffstats
path: root/ue5/array.hpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-06-03 17:26:57 +0200
committermanuel <manuel@nc8430.lan>2009-06-03 17:26:57 +0200
commit39b0cb9afeb53e9a1720bad64347e72d318c554a (patch)
tree1e3876cf3da06f33a8b7f96f790606637dd9701b /ue5/array.hpp
parente251dbf4e82efc3dcfe18f6d5d00ae3ce079d1bd (diff)
downloadooprog-39b0cb9afeb53e9a1720bad64347e72d318c554a.tar.gz
ooprog-39b0cb9afeb53e9a1720bad64347e72d318c554a.tar.bz2
ooprog-39b0cb9afeb53e9a1720bad64347e72d318c554a.zip
replacing 1xtab with 2xspace
implementing array
Diffstat (limited to 'ue5/array.hpp')
-rw-r--r--ue5/array.hpp136
1 files changed, 104 insertions, 32 deletions
diff --git a/ue5/array.hpp b/ue5/array.hpp
index 19cdc02..37a33b4 100644
--- a/ue5/array.hpp
+++ b/ue5/array.hpp
@@ -2,44 +2,116 @@
2#define ARRAY_H 2#define ARRAY_H
3 3
4#undef SOLVED_2 4#undef SOLVED_2
5//#define SOLVED_2 5#define SOLVED_2
6 6
7/* TODO Includes */ 7/* TODO:
8 * Angabe: Im Gegensatz zu den Beispielen bis jetzt ist die Verwendung
9 * der STL und Boostuntersagt!
10 */
11#include <utility> // for std::move
12#include <stdexcept> // for std::out_of_range
13#include <algorithm> // for std::fill_n + std::swap_ranges
8 14
9namespace Ti 15namespace Ti
10{ 16{
17 template<typename T, size_t N>
18 struct array
19 {
20 typedef T& reference;
21 typedef const T& const_reference;
22 typedef T* iterator;
23 typedef const T* const_iterator;
24 typedef size_t size_type;
11 25
12/* TODO */ 26 static_assert(N != 0, "array<T, 0> not allowed");
13struct array 27
14{ 28 void fill (const T& u)
15 /* TODO typedef */ 29 {
16 30 std::fill_n(begin(), size(), u);
17 /* TODO static_assert */ 31 }
18 32
19 /* TODO: 33 void swap (array<T,N> & other)
20 void fill (const T& u); 34 {
21 void swap (array<T,N> & other); 35 std::swap_ranges(begin(), end(), other.begin());
22 iterator begin(); 36 }
23 const_iterator begin() const; 37
24 iterator end(); 38 iterator begin()
25 const_iterator end() const; 39 {
26 size_type size() const; 40 return m_data;
27 size_type max_size() const; 41 }
28 bool empty() const; 42
29 reference operator[] (size_type n); 43 const_iterator begin() const
30 const_reference operator[] (size_type n) const; 44 {
31 reference at(size_type n); 45 return m_data;
32 const_reference at (size_type n) const; 46 }
33 T* data(); 47
34 */ 48 iterator end()
35 49 {
36private: 50 return m_data + size();
37 /* TODO data */ 51 }
38}; 52
39 53 const_iterator end() const
40/* TODO */ 54 {
41array/* TODO */&& make_array(); 55 return m_data + size();
56 }
57
58 size_type size() const
59 {
60 return N;
61 }
62
63 size_type max_size() const
64 {
65 return N;
66 }
67
68 bool empty() const
69 {
70 return false; /* size() == 0 */
71 }
72
73 reference operator[] (size_type n)
74 {
75 return m_data[n];
76 }
77
78 const_reference operator[] (size_type n) const
79 {
80 return m_data[n];
81 }
82
83 reference at(size_type n)
84 {
85 if (n >= size())
86 throw std::out_of_range("array::at");
87 return m_data[n];
88 }
89
90 const_reference at (size_type n) const
91 {
92 if (n >= size())
93 throw std::out_of_range("array::at");
94 return m_data[n];
95 }
96
97 T* data()
98 {
99 return m_data;
100 }
101
102 private:
103 T m_data[N];
104 };
105
106 /* TODO: was macht std::move() genau?! :) */
107 template<typename T, size_t N>
108 array<T, N>&& make_array()
109 {
110 return std::move(array<T, N>());
111 }
42 112
43} // namespace 113} // namespace
44 114
45#endif 115#endif
116
117/* vim: set et sw=2 ts=2: */