1 #ifndef PROTON_LIST_HEADER
2 #define PROTON_LIST_HEADER
11 template <
typename T,
typename allocT,
typename V >
12 bool has(
const std::list<T,allocT>& x, V&& val)
14 return std::find(x.begin(), x.end(), val)!=x.end();
17 template <
typename T,
typename A,
typename V>
18 std::list<T,A>& operator<<(std::list<T,A>& x, V&& val)
24 template <
typename T,
typename A,
typename V>
25 std::list<T,A>&
operator>>(std::list<T,A>& x, V& val)
33 template <
typename T,
typename A>
34 std::ostream& operator<<(std::ostream& s, std::list<T,A>& x)
79 template <
typename T,
typename A>
80 void sort(std::list<T,A>& x)
85 template <
typename T,
typename A>
86 T&
get(std::list<T,A>& x,
long i)
90 auto it=x.begin(),end=x.end();
97 PROTON_ERR(
"out of range: look up "<<i<<
" in a list whose size is " << j);
103 auto it=x.end(),begin=x.begin();
104 for(; j>i; --j,--it){
106 PROTON_ERR(
"out of range: look up "<<-j+i<<
" in a list whose size is " << -j);
113 template <
typename T,
typename A>
114 const T&
get(
const std::list<T,A>& x,
long i)
118 auto it=x.begin(),end=x.end();
119 for(; j<i; j++,++it){
125 PROTON_ERR(
"out of range: look up "<<i<<
" in a list whose size is " << j);
131 auto it=x.end(),begin=x.begin();
132 for(; j>i; --j,--it){
134 PROTON_ERR(
"out of range: look up "<<-j+i<<
" in a list whose size is " << -j);
142 template <
typename T,
typename A>
143 std::list<T,A> sub(
const std::list<T,A>& x,
long i)
145 typename std::list<T,A>::const_iterator it;
150 for(; j<i; j++,++it){
163 auto begin=x.begin();
164 for(; j>i; --j,--it){
172 std::copy(it, x.end(), std::back_inserter(r));
176 template <
typename T,
typename A>
177 std::list<T,A> sub(
const std::list<T,A>& x,
long first,
long last)
180 if(first>=0 && last>=0){
185 if(first<0 && last<0){
191 auto end=x.end(), begin=x.begin();
192 typename std::list<T,A>::const_iterator it;
198 for(; j<i; j++,++it){
211 for(; j>i; --j,--it){
221 if(first<0 && size>=0){
229 for(
long i=last-first;i>0;--i,++it){
238 typename std::list<T,A>::const_iterator it1;
244 for(; j<i; j++,++it1){
258 for(; j>i; --j,--it1){
265 std::copy(it,it1, std::back_inserter(r));
271 #endif // PROTON_LIST_HEADER