-
Notifications
You must be signed in to change notification settings - Fork 20
/
svector.h
124 lines (97 loc) · 2.77 KB
/
svector.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
This file is part of the FAST-ER machine learning system.
Copyright (C) 2008 Edward Rosten and Los Alamos National Laboratory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef SVECTOR_H
#define SVECTOR_H
#include <vector>
#include <iostream>
#ifdef SAFE_VECTOR
namespace std{
template<class T> class foovector: public std::vector<T>
{
public:
foovector()
{}
foovector(size_t n)
:std::vector<T>(n)
{}
template<class C> foovector(size_t n, const C& v)
:std::vector<T>(n, v)
{}
template<class C> foovector(const C& begin, const C& end)
:std::vector<T>(begin, end)
{}
foovector(const std::vector<T>& v)
:std::vector<T>(v)
{}
foovector& operator=(const std::vector<T>& v)
{
std::vector<T>::operator=(v);
return *this;
}
T&back() { return this->operator[](std::vector<T>::size()-1); }
const T&back() const { return this->operator[](std::vector<T>::size()-1); }
T&front() { return this->operator[]();}
const T&front() const { return this->operator[]();}
T&operator[](size_t n) {
try{
return std::vector<T>::at(n);
}
catch(...)
{
std::cerr << "Bad access n=" << n << " size=" << std::vector<T>::size() << endl;
throw;
}
}
const T&operator[](size_t n)const {
try{
return std::vector<T>::at(n);
}
catch(...)
{
std::cerr << "Bad access n=" << n << " size=" << std::vector<T>::size() << endl;
throw;
}
}
};
template<> class foovector<bool>: public std::vector<bool>
{
public:
foovector()
{}
foovector(size_t n)
:std::vector<bool>(n)
{}
template<class C> foovector(size_t n, const C& v)
:std::vector<bool>(n, v)
{}
template<class C> foovector(const C& begin, const C& end)
:std::vector<bool>(begin, end)
{}
foovector(const std::vector<bool>& v)
:std::vector<bool>(v)
{}
foovector& operator=(const std::vector<bool>& v)
{
std::vector<bool>::operator=(v);
return *this;
}
std::_Bit_reference operator[](size_t n) { return std::vector<bool>::at(n); }
const bool operator[](size_t n)const { return std::vector<bool>::at(n); }
};
}
#define vector foovector
#endif
#endif