完成全部构造函数
This commit is contained in:
@@ -94,6 +94,13 @@ namespace TinySTL{
|
|||||||
head.p = newNode();//add a dummy node
|
head.p = newNode();//add a dummy node
|
||||||
tail.p = head.p;
|
tail.p = head.p;
|
||||||
}
|
}
|
||||||
|
explicit list(size_type n, const value_type& val = value_type()){
|
||||||
|
ctorAux(n, val, std::is_integral<value_type>());
|
||||||
|
}
|
||||||
|
template <class InputIterator>
|
||||||
|
list(InputIterator first, InputIterator last){
|
||||||
|
ctorAux(first, last, std::is_integral<InputIterator>());
|
||||||
|
}
|
||||||
list(const list& l){
|
list(const list& l){
|
||||||
head.p = newNode();//add a dummy node
|
head.p = newNode();//add a dummy node
|
||||||
tail.p = head.p;
|
tail.p = head.p;
|
||||||
@@ -161,6 +168,19 @@ namespace TinySTL{
|
|||||||
//void sort(Compare comp);
|
//void sort(Compare comp);
|
||||||
void reverse();
|
void reverse();
|
||||||
private:
|
private:
|
||||||
|
void ctorAux(size_type n, const value_type& val, std::true_type){
|
||||||
|
head.p = newNode();//add a dummy node
|
||||||
|
tail.p = head.p;
|
||||||
|
while (n--)
|
||||||
|
push_back(val);
|
||||||
|
}
|
||||||
|
template <class InputIterator>
|
||||||
|
void ctorAux(InputIterator first, InputIterator last, std::false_type){
|
||||||
|
head.p = newNode();//add a dummy node
|
||||||
|
tail.p = head.p;
|
||||||
|
for (; first != last; ++first)
|
||||||
|
push_back(*first);
|
||||||
|
}
|
||||||
nodePtr newNode(const T& val = T()){
|
nodePtr newNode(const T& val = T()){
|
||||||
nodePtr res = nodeAllocator::allocate();
|
nodePtr res = nodeAllocator::allocate();
|
||||||
res->container = this;
|
res->container = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user