This is the mail archive of the
`libstdc++@gcc.gnu.org`
mailing list for the libstdc++ project.

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |

Other format: | [Raw text] |

*From*: Chris Jefferson <caj at cs dot york dot ac dot uk>*To*: libstdc++ at gcc dot gnu dot org*Date*: Tue, 10 Aug 2004 17:34:48 +0100*Subject*: Change to search_n

if(__n == 0) return __first; else __first = find(__i, __last, __val);

if(__n == 0) return __first; if(__i == __last) return __last; __first = __find(++__i, __last, __val);

template<typename _InputIter, typename _Integer, typename _Tp> inline _InputIter search_n(_InputIter __first, _InputIter __last, _Integer __count, const _Tp& __val) { // concept requirements __glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>) __glibcpp_function_requires(_EqualityComparableConcept< typename iterator_traits<_ForwardIter>::value_type>) __glibcpp_function_requires(_EqualityComparableConcept<_Tp>) return _search_n(__first, __last, __count, __val, __iterator_category(__first)); } template<typename _ForwardIter, typename _Integer, typename _Tp> _ForwardIter _search_n(_ForwardIter __first, _ForwardIter __last, _Integer __count, const _Tp& __val,random_access_iterator_tag) { if(__count<=0) return __first; while(__first<=__last) { if(__count>__last-__first) return __last; _ForwardIter __i = __first; __i+=__count-1; if(__i>=__last) return __last; if(*__i==__val) { int __equal=0; while((*__i==__val) && (__i>=__first)) { __equal++; __i--; } __i++; _ForwardIter __possibleFirst = __i; __i=__first+__count; while(*__i==__val && __i<__last && __equal<__count) { __equal++; __i++; } if(__equal==__count) return __possibleFirst; if(__i==__last) return __last; } __i++; __first=__i; } return __last; } template<typename _ForwardIter, typename _Integer, typename _Tp> _ForwardIter _search_n(_ForwardIter __first, _ForwardIter __last, _Integer __count, const _Tp& __val,input_iterator_tag) { if (__count <= 0) return __first; else { __first = find(__first, __last, __val); while (__first != __last) { typename iterator_traits<_ForwardIter>::difference_type __n = __count; --__n; _ForwardIter __i = __first; ++__i; while (__i != __last && __n != 0 && *__i == __val) { ++__i; --__n; } if (__n == 0) return __first; if (__i == __last) return __last; __first = find(++__i, __last, __val); } return __last; } }

**Follow-Ups**:**Re: Change to search_n***From:*Paolo Carlini

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |