SGI-STL 源码以及 word 注解版

时间:2012-10-24 10:45:52
【文件属性】:
文件名称:SGI-STL 源码以及 word 注解版
文件大小:2.07MB
文件格式:RAR
更新时间:2012-10-24 10:45:52
STL sgi #include #ifndef _RWSTD_NO_NAMESPACE namespace std { #endif // // Forward declare raw_storage_iterator // template class raw_storage_iterator; // // Non-modifying sequence operations. // template Function for_each (InputIterator first, InputIterator last, Function f) { while (first != last) f(*first++); return f; } template InputIterator find (InputIterator first, InputIterator last, const T& value) { while (first != last && *first != value) ++first; return first; } template InputIterator find_if (InputIterator first, InputIterator last, Predicate pred) { while (first != last && !pred(*first)) ++first; return first; } template ForwardIterator1 __find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, Distance*) { Distance d, d2; __initialize(d,Distance(0)); __initialize(d2,Distance(0)); distance(first2,last2,d); if (!d) return first1; distance(first1,last1,d2); ForwardIterator1 save = last1; while (d2 >= d) { if (equal(first2,last2,first1)) save = first1; __initialize(d2,Distance(0)); distance(++first1,last1,d2); } return save; } template ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2) { return __find_end(first1,last1,first2,last2, __distance_type(first1)); } template ForwardIterator1 __find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred, Distance*) { Distance d, d2; __initialize(d,Distance(0)); __initialize(d2,Distance(0)); distance(first2,last2,d); if (!d) return first1; distance(first1,last1,d2); ForwardIterator1 save = last1; while (d2 >= d) { if (equal(first2,last2,first1,pred)) save = first1; __initialize(d2,Distance(0)); distance(++first1,last1,d2); } return save; } template ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred) { return __find_end(first1,last1,first2,last2, pred,__distance_type(first1)); } template ForwardIterator1 find_first_of (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2) { if (first2 == last2) return first1; ForwardIterator1 next = first1; while (next != last1) { if (find(first2,last2,*next) != last2) return next; next++; } return last1; } template ForwardIterator1 find_first_of (ForwardIterator1 first1,ForwardIterator1 last1, ForwardIterator2 first2,ForwardIterator2 last2, BinaryPredicate pred) { if (first2 == last2) return first1; ForwardIterator1 next = first1; while (next != last1) { if (find_if(first2,last2,bind2nd(pred,*next)) != last2) return next; next++; } return last1; } template ForwardIterator adjacent_find (ForwardIterator first, ForwardIterator last) { if (first == last) return last; ForwardIterator next = first; while (++next != last) { if (*first == *next) return first; first = next; } return last; } template ForwardIterator adjacent_find (ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) { if (first == last) return last; ForwardIterator next = first; while (++next != last) { if (binary_pred(*first, *next)) return first; first = next; } return last; } #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template _TYPENAME iterator_traits::difference_type count (InputIterator first, InputIterator last, const T& value) { typename iterator_traits::difference_type n = 0; //RW_BUG: fix for bts-42842 while (first != last) if (*first++ == value) ++n; return n; } template _TYPENAME iterator_traits::difference_type count_if (InputIterator first, InputIterator last, Predicate pred) { typename iterator_traits::difference_type n = 0; //RW_BUG: fix for bts-42842 while (first != last) if (pred(*first++)) ++n; return n; } #endif /* _RWSTD_NO_CLASS_PARTIAL_SPEC */ #ifndef _RWSTD_NO_OLD_COUNT template void count (InputIterator first, InputIterator last, const T& value, Size& n) { while (first != last) if (*first++ == value) ++n; } template void count_if (InputIterator first, InputIterator last, Predicate pred, Size& n) { while (first != last) if (pred(*first++)) ++n; } #endif /* _RWSTD_NO_OLD_COUNT */ template pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) { while (first1 != last1 && *first1 == *first2) { ++first1; ++first2; } pair tmp(first1, first2); return tmp; } template pair mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred) { while (first1 != last1 && binary_pred(*first1, *first2)) { ++first1; ++first2; } pair tmp(first1, first2); return tmp; } template ForwardIterator1 __search (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, Distance1*, Distance2*) { Distance1 d1; __initialize(d1, Distance1(0)); distance(first1, last1, d1); Distance2 d2; __initialize(d2, Distance2(0)); distance(first2, last2, d2); if (d1 < d2) return last1; ForwardIterator1 current1 = first1; ForwardIterator2 current2 = first2; while (current2 != last2) { if (*current1++ != *current2++) if (d1-- == d2) return last1; else { current1 = ++first1; current2 = first2; } } return (current2 == last2) ? first1 : last1; } template ForwardIterator1 __search (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate binary_pred, Distance1*, Distance2*) { Distance1 d1; __initialize(d1, Distance1(0)); distance(first1, last1, d1); Distance2 d2; __initialize(d2, Distance2(0)); distance(first2, last2, d2); if (d1 < d2) return last1; ForwardIterator1 current1 = first1; ForwardIterator2 current2 = first2; while (current2 != last2) { if (!binary_pred(*current1++, *current2++)) if (d1-- == d2) return last1; else { current1 = ++first1; current2 = first2; } } return (current2 == last2) ? first1 : last1; } template ForwardIterator __search_n (ForwardIterator first, ForwardIterator last, Distance*, Size count, const T& value) { Distance d; __initialize(d, Distance(0)); distance(first, last, d); if (d < count || count <= 0) return last; Distance span = d - count; Size matches = 0; ForwardIterator current = first; while (current != last) { if (*current++ != value) { if (span < matches + 1) return last; span -= matches + 1; matches = 0; first = current; } else if (++matches == count) return first; } return last; } template ForwardIterator __search_n (ForwardIterator first, ForwardIterator last, Distance*, Size count, const T& value, BinaryPredicate pred) { Distance d; __initialize(d, Distance(0)); distance(first, last, d); if (d < count || count <= 0) return last; Distance span = d - count; Size matches = 0; ForwardIterator current = first; while (current != last) { if (!pred(*current++, value)) { if (span < matches + 1) return last; span -= matches + 1; matches = 0; first = current; } else if (++matches == count) return first; } return last; } // // Modifying sequence operations. // template OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result) { while (first != last) *result++ = *first++; return result; } template BidirectionalIterator2 copy_backward (BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result) { while (first != last) *--result = *--last; return result; } template ForwardIterator2 swap_ranges (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) { while (first1 != last1) iter_swap(first1++, first2++); return first2; } template OutputIterator transform (InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op) { while (first != last) *result++ = op(*first++); return result; } template OutputIterator transform (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation binary_op) { while (first1 != last1) *result++ = binary_op(*first1++, *first2++); return result; } template void replace (ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value) { while (first != last) { if (*first == old_value) *first = new_value; ++first; } } template void replace_if (ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value) { while (first != last) { if (pred(*first)) *first = new_value; ++first; } } template OutputIterator replace_copy (InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value) { while (first != last) { *result++ = *first == old_value ? new_value : *first; ++first; } return result; } template OutputIterator replace_copy_if (Iterator first, Iterator last, OutputIterator result, Predicate pred, const T& new_value) { while (first != last) { if(pred(*first)) *result++ = new_value; else *result++ = *first; ++first; } return result; }

网友评论

  • 相当不错,讲解详细
  • 非常不错,在看 STL 原码剖析的时候非常有用1
  • 源码很全,参考着《STL源码剖析》,收获很大。
  • 东西是好东西,不过俺是C菜鸟,这C++略屌···
  • 相当不错,讲解详细
  • 不错,很难得到,多谢!
  • 很好的东西,是我想要的!
  • 资源很好,很有用
  • 资源不错,只是好像源码和SGI官网上的有些不同
  • 不错,很难得到,多谢!
  • 相当不错,讲解详细
  • 不错,可惜是繁体的
  • 资源不错,只是好像源码和SGI官网上的有些不同,数量上要多一些
  • 在看侯捷先生的STL源码剖析,但是他的网站已经当掉了。。。所以从CSDN下载,很全,谢谢楼主。另外,源码和SGI不同是正常的,因为是G++ 2.9.1附带的,不是SGI原产。
  • 资源不错,只是好像源码和SGI官网上的有些不同,数量上要多一些