<utility><xutility>模板常见操作方法

//<utility><xutility>常见模板操作函数
  /*template <class _Ty, size_t _Size, class>
  inline void swap(_Ty(&_Left)[_Size], _Ty(&_Right)[_Size]) template <class _Ty,
 class>
 inline void swap(_Ty & _Left, _Ty & _Right) template <class _Ty> inline //交换
 void _Swap_adl(_Ty & _Left, _Ty & _Right)
 
 template <class _Ty1, class _Ty2>
  _NODISCARD constexpr bool operator==(const pair<_Ty1, _Ty2>& _Left, const
pair<_Ty1, _Ty2>& _Right)       //相等判断
 
template<class _Ty1, class _Ty2> _NODISCARD constexpr bool operator!=( const
pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) //不相等判断

    template <class _Ty1, class _Ty2>
      _NODISCARD constexpr bool operator<(const pair<_Ty1, _Ty2>& _Left, const
pair<_Ty1, _Ty2>& _Right)    //小于判断
 
 
 template <class _Ty1, class _Ty2> _NODISCARD constexpr bool operator>( const
pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) //大于判断
 
 template<class _Ty1,class _Ty2>
        _NODISCARD constexpr bool operator<=(const pair<_Ty1, _Ty2>& _Left,const
pair<_Ty1, _Ty2>& _Right) //小于等于

 template<class _Ty1,class _Ty2>
 _NODISCARD constexpr bool operator>=(const pair<_Ty1, _Ty2>& _Left,const
pair<_Ty1, _Ty2>& _Right) //大于等于判断
 
 template<class _Ty1,class _Ty2>
 _NODISCARD constexpr pair<_Unrefwrap_t<_Ty1>, _Unrefwrap_t<_Ty2>>
                make_pair(_Ty1&& _Val1, _Ty2&& _Val2) //构造pair
 */

  std::pair<std::_Unrefwrap_t<int>, std::_Unrefwrap_t<int>> pairs =
      std::make_pair<int, int>(1, 2);

  std::pair<std::_Unrefwrap_t<int>, std::_Unrefwrap_t<int>> pairs1 =
      std::make_pair<int, int>(3, 2);

  if (pairs == pairs1) {
  }

  int a[] = {1, 2, 3};
  int b[] = {4, 5, 6};

  // copy [_First, _Last) to [_Dest, ...)
  // std::copy<int*, int*>(a, a + 3, b);         //从位置a[0]开始 拷贝到b[0]
  // 拷贝3个
  std::copy<int*, int*>(&a[1], &a[1] + 2, &b[1]);  //从位置a[1] 拷贝2个数到b[0]

  //对标准容器操作
  std::vector<int> vec1;
  vec1.push_back(1);
  vec1.push_back(2);
  vec1.push_back(3);

  std::vector<int> vec2;
  vec2.push_back(4);
  vec2.push_back(5);
  vec2.push_back(6);
  std::vector<int>::iterator it1 = vec1.begin(), it2 = vec2.begin();
  //std::copy<std::vector<int>::iterator, std::vector<int>::iterator>(it1, it1 + 2, it2); //copy [_First, _Last) to [_Dest, ...)

  //std::move(it1, it1 + 3, it2); //=>std::move<std::vector<int>::iterator, std::vector<int>::iterator>(it1, it1 + 3, it2);
  //for (it2 = vec2.begin(); it2 != vec2.end(); it2++)
  //{
  //  std::cout << *it2 << std::endl;
  //}

  //for (it1 = vec1.begin(); it1 != vec1.end(); it1++) {
  //  std::cout << *it1 << std::endl;
  //}

  //copy [_First, _Last) backwards to [..., _Dest)
  /*std::copy_backward(it1, it1 + 2, it2 + 2);
   for (it2 = vec2.begin(); it2 != vec2.end(); it2++)
  {
    std::cout << *it2 << std::endl;
  }*/

  // move [_First, _Last) backwards to [..., _Dest)
  std::move_backward(it1, it1 + 2, it2 + 2);
  std::equal() compare [_First1, _Last1) to [_First2, ...)

 

详情参考<utility><xutility>

copy 是浅拷贝

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值