广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >C++模板以及实现vector实例详解
  • 483
分享到

C++模板以及实现vector实例详解

2024-04-02 19:04:59 483人浏览 泡泡鱼
摘要

目录函数模板类模板Vector实现简单的类模板实现代码及测试:win msvc编译器的实现:容器的空间配置器运算符重载与迭代器实现最终vector的实现代码总结函数模板 函数模板:是

函数模板

函数模板:是不进行编译的,因为类型还不知道

模板的实例化:函数调用点进行实例化

模板函数:才是要被编译器所编译的

模板类型参数:typyname/class

模板非类型参数:模板非类型形参的详细阐述

模板的实参推演:可以根据用户传入的实参的类型,来推导出模板类型参数的具体

模板的特例化(专用化)的实例化

模板函数、模板的特例化和非模板函数的重载关系:候选的函数中,优先在精确匹配中选择,优先选择普通函数,特例性更强的模版函数次之,然后是模版函数的特化版本,最后才是泛化版本。

模板代码是不能声明在.h,实现在.cpp,模板代码调用之前,一定要看到模板定义的地方,这样的话,模板才能够正常的实例化,产生能够被编译器编译的代码。模板代码都是放在头文件中,然后在源文件中直接进行#include


#define  _CRT_SECURE_NO_WARNINGS
#include <iOStream>
 
//函数模板
template<typename T> //定义一个模板参数列表
bool compare(T a, T b) {//compare 是一个函数模板
  std::cout << "template compare\n";
  return a > b;
}

 
//模板特例化: 针对compare函数模板,提供const char * 类型的特例化版本
template<>
bool compare<const char *>(const char* a, const char * b) {
  std::cout << "const char * compare\n";
  return strcmp(a, b) > 0;
}
 
//非模板函数,普通函数
bool compare(const char* a, const char * b) {
  std::cout << "nORMal compare\n";
  return strcmp(a, b) > 0;
}
 
int main()
{
  std::cout << compare<int>(1, 2) << std::endl;
  std::cout << compare<double>(1, 2) << std::endl;
  std::cout << compare(1, 2) << std::endl;//模板的实参推演 可以根据用户传入的实参的类型,来推导模板类型参数
  //编译器优先把compare处理成函数名,没有的话,才去找compare模板
  std::cout << compare("a", "b") << std::endl;//
  return 0;
}

类模板

实现一个顺序栈


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
 
template<typename T>
class  SeqStack
{
public:
  //构造和析构函数名不加<T> 其他出现模板的地方都加上类型参数列表
  SeqStack(int size = 10)
    :pstack_(new T[size])
  ,top_(0)
  ,size_(size){
    //初始化生成的指令更少,效率更高。仅调用默认构造函数(如果存在类成员)。赋值需要调用默认构造函数和赋值运算符
  }
  ~SeqStack() {
    if (pstack_) {
      delete[] pstack_;
      pstack_ = nullptr;
    }
  }
 
  SeqStack(const SeqStack<T>& stack)
    :top_(stack.top_),
    size_(stack.size_){
    pstack_ = new T[stack.size_];
    for (int i = 0; i < top_; ++i) {
      pstack_[i] = stack.pstack_[i];
    }
  }
  SeqStack<T>& operator=(const  SeqStack<T>&stack) {
    if (this == &stack) {
      return *this;
    }
 
    delete[] pstack_;
 
    top_ = stack.top_;
    size_ = stack.size_;
    pstack_ = new T[stack.size_];
    for (int i = 0; i < top_; ++i) {
      pstack_[i] = stack.pstack_[i];
    }
 
  }
 
  void push(const T& val) {
    if (full()) {
      resize();
    }
    pstack_[top_] = val;
    top_++;
  }
  void pop() {
    if (empty()) {
      return;
    }
    top_--;
  }
  T top() const {
    if (empty()) {
      throw "stack is empty";
    }
    return pstack_[top_-1];
  }
  bool full() const {
    return top_ == size_;
  }
  bool empty() const {
    return top_ == 0;
  }
protected:
 
 
private:
  void resize() {
    T * p = new T[size_ * 2];
    for (int i = 0; i < top_; ++i) {
      p[i] = pstack_[i];
    }
 
    size_ *= 2;
    delete pstack_;
    pstack_ = p;
  }
 
  T * pstack_;
  int top_;
  int size_;
};
 
int main()
{
  SeqStack<int> stack;
  for (int i = 0; i < 8; ++i) {
    stack.push(i);
  }
 
  while (!stack.empty())
  {
    std::cout << stack.top() << " ";
    stack.pop();
  }
  return 0;
}

Vector实现

        vector 的本质是一个数组,在vector 中需要有三个指针:

_first :指向数组的起始位置

_last:指向已经存放的最后一个元素的下一个位置

_end:指向数组长度的末尾元素的下一个位置。

数组的容量=_end-_first

数组中存放的元素个数=_last-_first

数组是否为空:_first == _last

数组是否已满:_last == _end

简单的类模板实现代码及测试:


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
 
template<typename T>
class vector
{
public:
  vector(int size = 10)
  {
    _first = new T[size];
    _last = _first;
    _end = _first + size;
  }
  ~vector()
  {
    delete[]_first;
    _first = _end = _last = nullptr;
  }
  vector(const vector<T>& rhs)
  {
    int size = rhs._end - rhs._first;
    _first = new T[size];
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _first[i] = rhs._first[i];
    }
    _last = _first + len;
    _end = _first + size;
  }
  vector<T>& operator=(const vector<T>& rhs)
  {
    if (this == &rhs)
      return *this;
 
    delete[]_first;
 
 
    int size = rhs._end - rhs._first;
    _first = new T[size];
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _first[i] = rhs._first[i];
    }
    _last = _first + len;
    _end = _first + size;
    return *this;
  }
  void push_back(const T& val) // 向容器末尾添加元素
  {
    if (full())
      expand();
    *_last++ = val;
  }
  void pop_back() // 从容器末尾删除元素
  {
    if (empty())
      return;
    --_last;
  }
  T back()const // 返回容器末尾的元素的值
  {
    return *(_last - 1);
  }
  bool full()const { return _last == _end; }
  bool empty()const { return _first == _last; }
  int size()const { return _last - _first; }
private:
  T* _first; // 指向数组起始的位置
  T* _last;  // 指向数组中有效元素的后继位置
  T* _end;   // 指向数组空间的后继位置
 
  void expand() // 容器的二倍扩容
  {
    int size = _end - _first;
    T *ptmp = new T[2 * size];
    for (int i = 0; i < size; ++i)
    {
      ptmp[i] = _first[i];
    }
    delete[]_first;
    _first = ptmp;
    _last = _first + size;
    _end = _first + 2 * size;
  }
};
 
 
class Test
{
public:
  Test() { std::cout << "Test()" << std::endl; }
  Test& operator=(const Test&t) { std::cout << "operator=" << std::endl; return *this; }
  ~Test() { std::cout << "~Test()" << std::endl; }
  Test(const Test&) { std::cout << "Test(const Test&)" << std::endl; }
};
 
 
int main()
{
  Test t1, t2;
  std::cout << "vector<Test> vec" << std::endl;
  vector<Test> vec;
  std::cout << "vector<Test> vec; push_back" << std::endl;
 
  vec.push_back(t1);
  vec.push_back(t2);
 
  std::cout << "vector<Test> vec; pop_back" << std::endl;
  vec.pop_back();
  return 0;
}

问题:在我们实现的vector构造函数中,使用new T[size]  :它做了两件事情

(1)开辟内存空间

(2)调用T类型的默认构造函数构造对象

其中第二步是一种浪费,因为我还没在vector 添加元素,提前构造一遍对象 然后在析构时候是否纯属多余。

同时:在实现pop_back()时,存在内存泄漏


  void pop_back() // 从容器末尾删除元素
  {
    if (empty())
      return;
    --_last;
  }

T

 仅仅将_last指针 --,并没有释放Test申请的资源。需要调用对象的析构函数

win msvc编译器的实现:


 
		// CLASS TEMPLATE vector
template<class _Ty,
	class _Alloc = allocator<_Ty>>
	class vector
		: public _Vector_alloc<_Vec_base_types<_Ty, _Alloc>>
	{	// varying size array of values
private:
	using _Mybase = _Vector_alloc<_Vec_base_types<_Ty, _Alloc>>;
	using _Alty = typename _Mybase::_Alty;
	using _Alty_traits = typename _Mybase::_Alty_traits;
......

系统的实现,除了数据类型外,还有一个allocator,它将开辟空间和构造对象分离开。

而这,也就是空间配置器做的工作;

容器的空间配置器

空间配置器主要有四个功能:

  1. 内存开辟 allocate(底层调用malloc);
  2. 内存释放 deallocate(底层调用free);
  3. 对象构造 construct(调用构造函数);
  4. 对象析构 destroy(调用析构函数

// 定义容器的空间配置器,和c++标准库的allocator实现一样
template<typename T>
struct Allocator
{
	T* allocate(size_t size) // 负责内存开辟
	{
		return (T*)malloc(sizeof(T) * size);
	}
	void deallocate(void* p) // 负责内存释放
	{
		free(p);
	}
	void construct(T* p, const T& val) // 负责对象构造
	{
		new (p) T(val); // 定位new
	}
	void destroy(T* p) // 负责对象析构
	{
		p->~T(); // ~T()代表了T类型的析构函数
	}
};

修改后的vector


 
#include <iostream>
// 定义容器的空间配置器,和C++标准库的allocator实现一样
template<typename T>
class Allocator
{
public:
  T* allocate(size_t size) // 负责内存开辟
  {
    return (T*)malloc(sizeof(T) * size);
  }
  void deallocate(void* p) // 负责内存释放
  {
    free(p);
  }
  void construct(T* p, const T& val) // 负责对象构造
  {
    new (p) T(val); // 定位new
  }
  void destroy(T* p) // 负责对象析构
  {
    p->~T(); // ~T()代表了T类型的析构函数
  }
};
 
 
template<typename T, typename Alloc = Allocator<T>>
class vector
{
public:
  vector(int size = 10)
  {
    // 需要把内存开辟和对象构造分开处理
    _first = _allocator.allocate(size);
    _last = _first;
    _end = _first + size;
  }
  ~vector()
  {
    // 析构容器有效的元素,然后释放_first指针指向的堆内存
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p); // 把_first指针指向的数组的有效元素进行析构操作
    }
    _allocator.deallocate(_first); // 释放堆上的数组内存
    _first = _last = _end = nullptr;
  }
  vector(const vector<T>& rhs)
  {
    int size = rhs._end - rhs._first;
    _first = _allocator.allocate(size);
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _allocator.construct(_first + i, rhs._first[i]);
    }
    _last = _first + len;
    _end = _first + size;
  }
  vector<T>& operator=(const vector<T>& rhs)
  {
    if (this == &rhs)
      return *this;
 
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p); // 把_first指针指向的数组的有效元素进行析构操作
    }
    _allocator.deallocate(_first);
 
    int size = rhs._end - rhs._first;
    _first = _allocator.allocate(size);
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _allocator.construct(_first + i, rhs._first[i]);
    }
    _last = _first + len;
    _end = _first + size;
    return *this;
  }
  void push_back(const T& val) // 向容器末尾添加元素
  {
    if (full())
      expand();
 
    _allocator.construct(_last, val);
    _last++;
  }
  void pop_back() // 从容器末尾删除元素
  {
    if (empty())
      return;
 
    // 不仅要把_last指针--,还需要析构删除的元素
    --_last;
    _allocator.destroy(_last);
  }
  T back()const // 返回容器末尾的元素的值
  {
    return *(_last - 1);
  }
  bool full()const { return _last == _end; }
  bool empty()const { return _first == _last; }
  int size()const { return _last - _first; }
private:
  T* _first; // 指向数组起始的位置
  T* _last;  // 指向数组中有效元素的后继位置
  T* _end;   // 指向数组空间的后继位置
  Alloc _allocator; // 定义容器的空间配置器对象
 
  void expand() // 容器的二倍扩容
  {
    int size = _end - _first;
    T* ptmp = _allocator.allocate(2 * size);
    for (int i = 0; i < size; ++i)
    {
      _allocator.construct(ptmp + i, _first[i]);
    }
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p);
    }
    _allocator.deallocate(_first);
    _first = ptmp;
    _last = _first + size;
    _end = _first + 2 * size;
  }
};
 
 
class Test
{
public:
  Test() { std::cout << "Test()" << std::endl; }
  Test& operator=(const Test&t) { std::cout << "operator=" << std::endl; return *this; }
  ~Test() { std::cout << "~Test()" << std::endl; }
  Test(const Test&) { std::cout << "Test(const Test&)" << std::endl; }
};
 
 
int main()
{
  Test t1, t2;
  std::cout << "vector<Test> vec" << std::endl;
  vector<Test> vec;
  std::cout << "vector<Test> vec; push_back" << std::endl;
 
  vec.push_back(t1);
  vec.push_back(t2);
 
  std::cout << "vector<Test> vec; pop_back" << std::endl;
  vec.pop_back();
 
  std::cout << "end" << std::endl;
  return 0;
}

 现在的效果就和msvc实现的vector相同了

运算符重载与迭代器实现


  
  
  
  class iterator
  {
  public:
    iterator(T*p=nullptr) :_ptr(p) {}
    iterator(const iterator& iter) :_ptr(iter._ptr) {}
    //前置++
    iterator& operator++() {
      _ptr++;
      return *this;
    }
 
    //后置++
    iterator operator++(int) {
      iterator tmp(*this);
      _ptr++;
      return tmp;
    }
 
    //解引用
    T& operator*() {
      return *_ptr;
    }
 
    // !=
    bool operator!=(const iterator& iter)const {
      return _ptr != iter._ptr;
    }
 
  private:
    T * _ptr;
  };
 
  //迭代器方法
  iterator begin() { return iterator(_first); }
  iterator end() { return iterator(_last);}
 
  //运算符重载[]
  T& operator[](int index) {
    if (index < 0 || index >= size()) {
      throw "OutofRangeException";
    }
 
    return _first[index];
  }

最终vector的实现代码


 
#include <iostream>
// 定义容器的空间配置器,和C++标准库的allocator实现一样
template<typename T>
class Allocator
{
public:
  T* allocate(size_t size) // 负责内存开辟
  {
    return (T*)malloc(sizeof(T) * size);
  }
  void deallocate(void* p) // 负责内存释放
  {
    free(p);
  }
  void construct(T* p, const T& val) // 负责对象构造
  {
    new (p) T(val); // 定位new
  }
  void destroy(T* p) // 负责对象析构
  {
    p->~T(); // ~T()代表了T类型的析构函数
  }
};
 
 
template<typename T, typename Alloc = Allocator<T>>
class vector
{
public:
  vector(int size = 10)
  {
    // 需要把内存开辟和对象构造分开处理
    _first = _allocator.allocate(size);
    _last = _first;
    _end = _first + size;
  }
  ~vector()
  {
    // 析构容器有效的元素,然后释放_first指针指向的堆内存
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p); // 把_first指针指向的数组的有效元素进行析构操作
    }
    _allocator.deallocate(_first); // 释放堆上的数组内存
    _first = _last = _end = nullptr;
  }
  vector(const vector<T>& rhs)
  {
    int size = rhs._end - rhs._first;
    _first = _allocator.allocate(size);
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _allocator.construct(_first + i, rhs._first[i]);
    }
    _last = _first + len;
    _end = _first + size;
  }
  vector<T>& operator=(const vector<T>& rhs)
  {
    if (this == &rhs)
      return *this;
 
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p); // 把_first指针指向的数组的有效元素进行析构操作
    }
    _allocator.deallocate(_first);
 
    int size = rhs._end - rhs._first;
    _first = _allocator.allocate(size);
    int len = rhs._last - rhs._first;
    for (int i = 0; i < len; ++i)
    {
      _allocator.construct(_first + i, rhs._first[i]);
    }
    _last = _first + len;
    _end = _first + size;
    return *this;
  }
  void push_back(const T& val) // 向容器末尾添加元素
  {
    if (full())
      expand();
 
    _allocator.construct(_last, val);
    _last++;
  }
  void pop_back() // 从容器末尾删除元素
  {
    if (empty())
      return;
 
    // 不仅要把_last指针--,还需要析构删除的元素
    --_last;
    _allocator.destroy(_last);
  }
  T back()const // 返回容器末尾的元素的值
  {
    return *(_last - 1);
  }
  bool full()const { return _last == _end; }
  bool empty()const { return _first == _last; }
  int size()const { return _last - _first; }
 
  //运算符重载[]
  T& operator[](int index) {
    if (index < 0 || index >= size()) {
      throw "OutofRangeException";
    }
 
    return _first[index];
  }
 
  
  
  
  class iterator
  {
  public:
    iterator(T*p=nullptr) :_ptr(p) {}
    iterator(const iterator& iter) :_ptr(iter._ptr) {}
    //前置++
    iterator& operator++() {
      _ptr++;
      return *this;
    }
 
    //后置++
    iterator operator++(int) {
      iterator tmp(*this);
      _ptr++;
      return tmp;
    }
 
    //解引用
    T& operator*() {
      return *_ptr;
    }
 
    // !=
    bool operator!=(const iterator& iter)const {
      return _ptr != iter._ptr;
    }
 
  private:
    T * _ptr;
  };
 
  //迭代器方法
  iterator begin() { return iterator(_first); }
  iterator end() { return iterator(_last);}
private:
  T* _first; // 指向数组起始的位置
  T* _last;  // 指向数组中有效元素的后继位置
  T* _end;   // 指向数组空间的后继位置
  Alloc _allocator; // 定义容器的空间配置器对象
 
  void expand() // 容器的二倍扩容
  {
    int size = _end - _first;
    T* ptmp = _allocator.allocate(2 * size);
    for (int i = 0; i < size; ++i)
    {
      _allocator.construct(ptmp + i, _first[i]);
    }
    for (T* p = _first; p != _last; ++p)
    {
      _allocator.destroy(p);
    }
    _allocator.deallocate(_first);
    _first = ptmp;
    _last = _first + size;
    _end = _first + 2 * size;
  }
};
 
 
class Test
{
public:
  Test() { std::cout << "Test()" << std::endl; }
  Test& operator=(const Test&t) { std::cout << "operator=" << std::endl; return *this; }
  ~Test() { std::cout << "~Test()" << std::endl; }
  Test(const Test&) { std::cout << "Test(const Test&)" << std::endl; }
};
 
 
int main()
{
  Test t1, t2;
  std::cout << "vector<Test> vec" << std::endl;
  vector<Test> vec;
  std::cout << "vector<Test> vec; push_back" << std::endl;
 
  vec.push_back(t1);
  vec.push_back(t2);
 
  std::cout << "vector<Test> vec; pop_back" << std::endl;
  vec.pop_back();
 
  std::cout << "end" << std::endl;
 
  vector<Test>::iterator it = vec.begin();
  for (; it != vec.end(); ++it) {
    std::cout << "iterator" << " ";
  }
 
  return 0;
}

总结

到此这篇关于C++模板以及实现vector的文章就介绍到这了,更多相关C++模板以及实现vector内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: C++模板以及实现vector实例详解

本文链接: https://www.lsjlt.com/news/157509.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • C++模板以及实现vector实例详解
    目录函数模板类模板Vector实现简单的类模板实现代码及测试:win msvc编译器的实现:容器的空间配置器运算符重载与迭代器实现最终vector的实现代码总结函数模板 函数模板:是...
    99+
    2022-11-12
  • 详解C++中vector的理解以及模拟实现
    目录vector介绍vector常见函数介绍vector模拟实现及迭代器失效讲解vector介绍 vector文档 1.vector是表示可变大小数组的序列容器。 2.就像数组一样,...
    99+
    2023-03-08
    C++ vector实现 C++ vector
  • C++中vector的模拟实现实例详解
    目录vector接口总览 默认成员函数 构造函数 拷贝构造 赋值重载 析构函数 迭代器相关函数 begin和end 容量相关函数 size和capacity reserve resi...
    99+
    2022-11-12
  • C++模拟实现vector流程详解
    目录模拟vector总结模拟vector 我们可以通过模板实现类似vector的类。我们实现一个StrVecTemp类,其内部通过allocator开辟空间,存储的类型用T来表示,T...
    99+
    2022-11-13
    C++ vector容器 C++ vector
  • C++超详细讲解模拟实现vector
    目录1. 模拟实现vector2. vector常用接口2.1 reserve2.2 resize2.3 push_back2.4 pop_back()2.5 insert2.6 e...
    99+
    2022-11-13
  • C++动态数组模版类Vector实例详解
    目录1.实现机制2.代码实现3.测试运行总结1.实现机制 内部主要通过m_capacity数组容量成员和m_length数组有效长度成员来维护一个T* data数组空间. 内部默认分...
    99+
    2022-11-13
  • C++类模板实战之vector容器的实现
    目录案例要求完成步骤1、封装数组类属性并完成有参构造以及析构函数2、提供对应的深拷贝构造函数防止调用析构时出错3、重载类内的赋值运算符防止浅拷贝问题出现4、提供尾部插入和删除的方法5...
    99+
    2022-11-13
  • C++  STL _ Vector使用及模拟实现
    目录1.Vector的介绍1.1 Vector的介绍2.Vector的使用2.1 vector的定义2.2 vector 迭代器的使用 2.3 vector的空间增长问题3...
    99+
    2022-11-13
  • C++模板基础之函数模板与类模板实例详解
    目录泛型编程 函数模板 函数模板的概念 函数模板的格式 函数模板的原理 函数模板的实例化 函数模板的匹配原则 类模板 类模板的定义格式 类模板的实例化 总结泛型编程  ...
    99+
    2022-11-12
  • C++模拟实现vector的示例代码
    目录1.前言2.vector介绍3.vector模拟实现3.1 迭代器接口3.2 vector元素操作3. 3 构造与析构1.前言 大家在学习C++的时候一定会学到STL(标准模板库...
    99+
    2022-11-13
  • C++中STL vector的模拟实现示例
    这篇文章主要介绍C++中STL vector的模拟实现示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1. vector的介绍和使用vector是表示可变大小数组的序列容器。就像数组一样,vector也采用的连续存...
    99+
    2023-06-14
  • C++使用宏函数实现单例模板详解
    目录ISingleton.hpp使用方式Aclass.hAclass.cppmain.c在我们日常开发中,无可避免需要使用单例模式进行设计类对象,那么实际上我们写单例格式基本都是一样...
    99+
    2023-02-10
    C++宏函数实现单例模板 C++ 单例模板 C++宏函数
  • C++模拟实现vector示例代码图文讲解
    目录vector的模拟实现使用memcpy拷贝问题vector的模拟实现 #include <iostream> using namespace std; #includ...
    99+
    2023-02-27
    C++ vector模拟实现 C++ vector模拟
  • c++中vector模拟实现的示例分析
    这篇文章将为大家详细讲解有关c++中vector模拟实现的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、vector是什么?vector是表示可变大小数组的序列容器,它也采用连续存储空间来存储...
    99+
    2023-06-14
  • 【C++进阶(二)】STL大法--vector的深度剖析以及模拟实现
    💓博主CSDN主页:杭电码农-NEO💓   ⏩专栏分类:C++从入门到精通⏪   🚚代码仓库:NEO的学习日记🚚   ...
    99+
    2023-09-06
    c++ java 开发语言
  • Vue的模板语法以及实战案例
    目录前言一、双大括号表达式二、插值2.1文本2.2 原始 HTML2.3 特性2.4 javascript 表达式三、指令3.1 参数3.2 动态参数3.3 修饰符四、指令缩写4.1...
    99+
    2022-11-13
  • C++入门之vector的底层实现详解
    目录前言定义初始结构声明构造函数容量有关操作获取有效数据大小size()获取数据容量capacity()增加容量reserve()重置大小resize()迭代器数据操作尾插push_...
    99+
    2022-11-12
  • Django模板继承与模板的导入实例详解
    目录一:模版的继承1.什么是模板继承2.使用继承流程原理3.模板继承语法二:模板的继承使用1.案例需求2.总结模板继承三:模版的导入1.模板导入2.模板导入格式3.模板导入使用4.使...
    99+
    2022-11-13
  • 线段树详解以及C++实现代码
    目录应用场景算法思想查询操作修改操作算法实现建树查询修改总结应用场景 假设有这样的问题:有n个数,m次操作,操作分为:修改某一个数或者查询一段区间的值 分析下,如果针对数组元素的修改...
    99+
    2022-11-12
  • django中模板继承与ModelForm实例详解
    目录模板的继承form和ModelForm使用方法总结模板的继承 完美在写html的时候会发现,自己多个html文件中又好多东西是一样的,包括静插件的引入 还有有些简单的css样式都...
    99+
    2022-11-10
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作