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:  } 
  • 相关阅读:
    内存队列使用Channels
    笔记20210101mongodb
    管道式的开发模式
    企业级应用架构设计
    再入历史旧坑
    路径问题 再次记录
    mongdb驱动的问题
    使用Bumblebee记录
    我和小兔子不得不说的消息v2
    流程设计器jQuery + svg/vml(Demo7
  • 原文地址:https://www.cnblogs.com/justinzhang/p/2667210.html
Copyright © 2011-2022 走看看