Rudiments
staticarrayinlines.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information.
3 
4 #include <rudiments/private/new.h>
5 
6 template< class valuetype, uint64_t length >
7 inline
9  len=length;
10  data=new valuetype[len];
11 }
12 
13 template< class valuetype, uint64_t length >
14 inline
17  len=v.len;
18  data=new valuetype[len];
19  for (uint64_t i=0; i<len; i++) {
20 
21  // Why not just:
22  // *data[i]=*v.data[i];
23  //
24  // Some compilers get confused and think that
25  // *data[i]=*v.data[i]
26  // means
27  // *((data[i])->operator=(*v.data[i]))
28  // and no carefully placed parentheses help.
29  //
30  // This silliness sorts out the problem.
31  valuetype *a=&(data[i]);
32  valuetype *b=&(v.data[i]);
33  *a=*b;
34  }
35 }
36 
37 template< class valuetype, uint64_t length >
38 inline
41  if (this!=&v) {
42  len=v.len;
43  data=new valuetype[len];
44  for (uint64_t i=0; i<len; i++) {
45 
46  // Why not just:
47  // *data[i]=*v.data[i];
48  //
49  // Some compilers get confused and think that
50  // *data[i]=*v.data[i]
51  // means
52  // *((data[i])->operator=(*v.data[i]))
53  // and no carefully placed parentheses help.
54  //
55  // This silliness sorts out the problem.
56  valuetype *a=&(data[i]);
57  valuetype *b=&(v.data[i]);
58  *a=*b;
59  }
60  }
61  return *this;
62 }
63 
64 template< class valuetype, uint64_t length >
65 inline
67  delete[] data;
68 }
69 
70 template< class valuetype, uint64_t length >
71 inline
72 valuetype &staticarray<valuetype,length>::operator[](uint64_t index) {
73  return data[index];
74 }
75 
76 template< class valuetype, uint64_t length >
77 inline
79  return len;
80 }
81 
82 template< class valuetype, uint64_t length >
83 inline
85  for (uint64_t i=0; i<len; i++) {
86  ((valuetype *)&data[i])->~valuetype();
87  new(&data[i]) valuetype;
88  }
89 }
valuetype & operator[](uint64_t index)
Definition: staticarrayinlines.h:72
uint64_t getLength() const
Definition: staticarrayinlines.h:78
staticarray< valuetype, length > & operator=(const staticarray< valuetype, length > &v)
Definition: staticarrayinlines.h:39
staticarray()
Definition: staticarrayinlines.h:8
Definition: staticarray.h:37
void clear()
Definition: staticarrayinlines.h:84
~staticarray()
Definition: staticarrayinlines.h:66