成都創新互聯是一家專注于成都網站設計、成都做網站與策劃設計,官渡網站建設哪家好?成都創新互聯做網站,專注于網站建設10余年,網設計領域的專業建站公司;建站業務涵蓋:官渡等地區。官渡做網站價格咨詢:13518219792
#pragma once struct InputIteratorTag {}; struct OutputIteratorTag {}; struct ForwardIteratorTag : public InputIteratorTag {}; struct BidirectionalIteratorTag : public ForwardIteratorTag {}; struct RandomAccessIteratorTag : public BidirectionalIteratorTag {}; template<class T> struct InputIterator { //typedef T ValueType; //typedef Distance DifferenceType; //typedef T* Pointer; //typedef T& Reference; typedef InputIteratorTag IteratorCategory; //迭代器的類型 ( 包括上面那5個struct ) }; template<class Iterator> struct IteratorTraits { //typedef typename Iterator::ValueType ValueType; //typedef typename Iterator::DifferenceType DifferenceType; //typedef typename Iterator::Pointer Pointer; //typedef typename Iterator::Reference Reference; typedef typename InputIterator<Iterator>::IteratorCategory IteratorCategory; }; template<class T> struct IteratorTraits<T*> //內置類型的特化版本 { typedef RandomAccessIteratorTag IteratorCategory; }; template <class InputIterator> inline size_t Distance(InputIterator first, InputIterator last) { return _Distance(first, last, IteratorTraits<InputIterator>::IteratorCategory() ); //這里第三個參數 并沒有實際意義,不過正是它的存在,讓_Distance實現重載 } template <class InputIterator> inline size_t _Distance(InputIterator first, InputIterator last, RandomAccessIteratorTag) { return last - first; } template <class InputIterator> inline size_t _Distance(InputIterator first, InputIterator last, InputIteratorTag) { size_t n = 0; while (first != last) { ++first; ++n; } return n; }
當前標題:STL中迭代器(Iterator)的簡單實現
網站地址:http://vcdvsql.cn/article10/pcohgo.html
成都網站建設公司_創新互聯,為您提供服務器托管、網頁設計公司、品牌網站建設、營銷型網站建設、手機網站建設、面包屑導航
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯