⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foreach2.h

📁 UC Library Extensions UnderC comes with a pocket implementation of the standard C++ libraries, wh
💻 H
字号:
// foreach2.h: Implementing FOR_EACH without using typeof

class IterBase {
 public:
   virtual bool next()=0;
};

template <class V, class C>
 class Iter: public IterBase {
 protected:
  V& _ref;
  C::iterator _ci, _ci_end;

 public:
  Iter(V& ref, C& con)
   : _ref(ref), _ci_end(con.end()), _ci(con.begin())
  {  }

  bool next ()
  { 
    if (_ci == _ci_end) return false;
    _ref = *_ci;
    _ci++; 
    return true;
  }

};

template <class C>
 IterBase *_make_iter(C::value_type& ref, C& con)
 {
   return new Iter<C::value_type,C> (ref,con);
 } 

#define FOR_EACH(i,li) \
  for(std::auto_ptr<IterBase> it(_make_iter(i,(li))); \
     it->next();) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -