This is my first blog article.如有写得不清晰之处多多谅解!
我是Link Code。今天我们要实现C++ STL的vector的升级版。(捂脸,你们去学习deque不就好了,deque是vector的升级版啊)
原来vector没有push_front和pop_front,我们将要加上去。
还有更多未知功能,看我怎么写。
先插入目前已知代码吧!
#include<memory> #include<cstddef> #include<iterator> #include<initializer_list> #if __cplusplus<201103L #define DEFAULT_NOEXCEPT #else #define DEFAULT_NOEXCEPT noexcept #endif template<class T,class Allocator=std::allocator<T> > class basic_dynamic_array { public: typedef T value_type; typedef Allocator allocator_type; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; #if __cplusplus<201103L typedef typename Allocator::reference reference; typedef typename Allocator::const_reference const_reference; typedef typename Allocator::pointer pointer; typedef typename Allocator::const_pointer const_pointer; #else typedef value_type& reference; typedef const value_type& const_reference; typedef typename std::allocator_traits<Allocator>::pointer pointer; typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; #endif typedef value_type* iterator; typedef const value_type* const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; static const size_type npos = -1; private: }; int __cdecl main(void) { return 0; }
这是初始代码,从我定义的静态常量就可以看出来是有find函数的吧。npos的定义:https://zh.cppreference.com/w/cpp/string/basic_string/npos
我将先会实现vector的基本功能,然后添加扩展功能。
作业:
思考private部分该写什么变量。
--2020.3.19
--from Link Code