保存一下
  • 板块灌水区
  • 楼主_czx6666_
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/1/16 11:27
  • 上次更新2024/1/16 16:32:24
查看原帖
保存一下
1056023
_czx6666_楼主2024/1/16 11:27
#include<bits/stdc++.h>
using namespace std;
template<typename T>class V{
    public:
        typedef T value_type;
        typedef typename vector<T>::size_type size_type;
        V();
        V(initializer_list<T> il);
        size_type size()const{return date->size();}
        bool empty()const{return date->empty();}
        void push_back(const T &t){date->push_back(t);}
        void push_back(T &&t){date->push_back(move(t));}
        void pop_back();
        T& back();
        T& operator[](size_type i);
    private:
        shared_ptr<vector<T>> date;
        void chack(size_type i,const string &msg)const;
};
template<typename T>void V<T>::chack(size_type i,const string &msg)const{
    if(i>=date->size())
        throw out_of_range(msg);
}
template<typename T>T& V<T>::back(){
    chack(0,"back on empty V");
    return date->back();
}
template<typename T>T& V<T>::operator[](size_type i){
    chack(i,"subscript out of range");
    return (*date)[i];
}
template<typename T>void V<T>::pop_back(){
    chack(0,"pop_back on empty V");
    date->pop_back();
}
int main(){





    return 0;
}
2024/1/16 11:27
加载中...