1 /******************************************************************
2 * 21 days: a game for programmers
3 * Copyright (C) 2014 Maxim Grishin
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * This file contains a part of file "/include/vector" from menuetlibc
22 * adapted to the developer's needs.
24 * 1. "*__cdecl" replaced with "* __attribute__((cdecl))" in order
25 * to compile a C++ project.
26 * 2. Added front() methods with the following code:
27 * T& front() {return data[0];}
30 ********************************************************************/
35 extern void * __attribute__((cdecl)) operator new(size_t);
36 inline void * __attribute__((cdecl)) operator new(size_t, void *_P
) {
40 template<class T
> class vector21
{
45 typedef unsigned size_type
;
47 vector21():length(0),allocated(0),data(NULL
) {}
48 ~vector21() {for (unsigned i
=length
;i
--;)data
[i
].~T();free(data
);}
49 unsigned size() const {return length
;}
50 void clear() {length
=0;}
51 T
& operator[](unsigned pos
) {return data
[pos
];}
52 T
* begin() {return data
;}
53 T
* end() {return data
+length
;}
54 void push_back(const T
& x
) {
55 if (length
==allocated
){
57 data
=(T
*)realloc(data
,allocated
*sizeof(T
));
59 new (data
+length
++) T(x
);
61 bool empty() const {return length
==0;}
62 void pop_back() {data
[--length
].~T();}
63 T
& back() {return data
[length
-1];}
64 T
& front() {return data
[0];}
65 iterator
erase(iterator it
) {
67 while (++a
!= data
+length
) {
73 /*iterator*/T
* insert(iterator where
, const T
& what
= T()) {
75 if (length
==allocated
) {
77 data
=(T
*)realloc(data
,allocated
*sizeof(T
));