zoukankan      html  css  js  c++  java
  • stl iterator traits

       1:  /*
       2:  author:justinzhang
       3:  email:uestczhangchao@gmail.com
       4:  time:2012-8-23 10:28:53
       5:  desc: value_type , from <the annotated stl source>, chapter 3, p86
       6:  iterator_traits will be coflict with system, so i use another name.
       7:  */
       8:  #include<iostream>
       9:  using namespace std;
      10:   
      11:  template <class T>
      12:  struct MyIter
      13:  {
      14:      typedef T value_type;
      15:      T* ptr;
      16:      MyIter(T* p=0) : ptr(p){}
      17:      T& operator*() const {return *ptr;}
      18:      
      19:  };
      20:  template <class I>
      21:  struct iterator_traitss
      22:  {
      23:      typedef typename I::value_type value_type;    
      24:  };
      25:   
      26:  template <class T>
      27:  struct iterator_traitss<T*>
      28:  {
      29:      typedef T value_type;
      30:  };
      31:   
      32:  template <class I>
      33:  typename iterator_traitss<I>::value_type
      34:  func(I ite)
      35:  {
      36:      return *ite;
      37:  }
      38:   
      39:  int main()
      40:  {
      41:  MyIter<int> ite(new int(8));
      42:  cout << func(ite)<<endl;
      43:  return 0;
      44:  } 
  • 相关阅读:
    CAN Timing Sample Point
    宋体汉字字号和点阵大小对应关系
    有趣的心理测试——借船过河
    有源蜂鸣器与无源蜂鸣器的区别(转)
    VAG DMA protocol
    STM32 USB CAN 学习笔记
    STM32 CANBus RAM Layout
    LPC43XX JTAG Scan Chain
    Multiplexing SDIO Devices Using MAX II or CoolRunner-II CPLD
    LPC43xx SGPIO DMA and Interrupts
  • 原文地址:https://www.cnblogs.com/justinzhang/p/2667210.html
Copyright © 2011-2022 走看看