[go: up one dir, main page]

Menu

[408bb9]: / common / simple_vector.h  Maximize  Restore  History

Download this file

89 lines (80 with data), 1.6 kB

 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef SIMPLE_VECTOR_HEADER
#define SIMPLE_VECTOR_HEADER
__STXXL_BEGIN_NAMESPACE
template < class _Tp /*, class _Alloc=__STL_DEFAULT_ALLOCATOR(_Tp) */ >
class simple_vector
{
simple_vector ()
{
}
public:
typedef size_t size_type;
typedef _Tp value_type;
// typedef simple_alloc<_Tp, _Alloc> _data_allocator;
protected:
size_type _size;
value_type *_array;
private:
simple_vector & operator = (const simple_vector &); // forbidden
simple_vector(const simple_vector &); // forbidden
public:
typedef value_type *iterator;
typedef const value_type *const_iterator;
typedef value_type & reference;
typedef const value_type & const_reference;
simple_vector (size_type sz):_size (sz)
{
//assert(sz);
// _array = _data_allocator.allocate(sz);
_array = new _Tp[sz];
}
void swap(simple_vector & obj)
{
std::swap(_size,obj._size);
std::swap(_array,obj._array);
}
~simple_vector ()
{
// _data_allocator.deallocate(_array,_size);
delete [] _array;
}
iterator begin ()
{
return _array;
}
const_iterator begin () const
{
return _array;
}
iterator end ()
{
return _array + _size;
}
const_iterator end () const
{
return _array + _size;
}
size_type size () const
{
return _size;
}
reference operator [] (size_type i)
{
return *(begin () + i);
}
const_reference operator [] (size_type i) const
{
return *(begin () + i);
}
};
__STXXL_END_NAMESPACE
namespace std
{
template <class Tp_>
void swap( stxxl::simple_vector<Tp_> & a,
stxxl::simple_vector<Tp_> & b)
{
a.swap(b);
}
}
#endif