BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FTList.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdexcept>
4#include <vector>
5
6template <typename T> class FTList : public std::vector<T> {
7public:
8 using std::vector<T>::vector;
9
10 typename std::vector<T>::iterator erase( typename std::vector<T>::iterator it ) {
11
12 if ( it < this->begin() || it > this->end() )
13 { throw std::runtime_error( "list::erase: iterator out of range" ); }
14
15 if ( it == this->end() - 1 )
16 {
17 std::vector<T>::pop_back();
18 return this->end();
19 }
20
21 T lastElem = std::move( this->back() );
22 std::vector<T>::pop_back();
23
24 *it = std::move( lastElem );
25
26 return it;
27 }
28
29 typename std::vector<T>::iterator erase( typename std::vector<T>::const_iterator it ) {
30
31 if ( it < this->begin() || it > this->end() )
32 { throw std::runtime_error( "list::erase: iterator out of range" ); }
33
34 if ( it == this->end() - 1 )
35 {
36 std::vector<T>::pop_back();
37 return this->end();
38 }
39
40 T lastElem = std::move( this->back() );
41 std::vector<T>::pop_back();
42
43 *it = std::move( lastElem );
44
45 return it;
46 }
47};
Definition FTList.h:6
std::vector< T >::iterator erase(typename std::vector< T >::const_iterator it)
Definition FTList.h:29
std::vector< T >::iterator erase(typename std::vector< T >::iterator it)
Definition FTList.h:10