fixed problem with an iterator being == end and dereferencing it

[SVN r28142]
This commit is contained in:
Victor A. Wagner Jr.
2005-04-12 04:37:06 +00:00
parent 2074344846
commit 0f827f89cf

View File

@ -28,7 +28,7 @@ namespace boost {
// find a subsequence in the sequence ( functor ) // find a subsequence in the sequence ( functor )
/* /*
Returns a pair <begin,end> marking the subsequence in the sequence. Returns a pair <begin,end> marking the subsequence in the sequence.
If the find fails, functor returns <End,End> If the find fails, functor returns <End,End>
*/ */
template<typename SearchIteratorT,typename PredicateT> template<typename SearchIteratorT,typename PredicateT>
@ -38,9 +38,9 @@ namespace boost {
// Construction // Construction
template< typename SearchT > template< typename SearchT >
first_finderF( const SearchT& Search, PredicateT Comp ) : first_finderF( const SearchT& Search, PredicateT Comp ) :
m_Search(begin(Search), end(Search)), m_Comp(Comp) {} m_Search(begin(Search), end(Search)), m_Comp(Comp) {}
first_finderF( first_finderF(
search_iterator_type SearchBegin, search_iterator_type SearchBegin,
search_iterator_type SearchEnd, search_iterator_type SearchEnd,
PredicateT Comp ) : PredicateT Comp ) :
@ -49,8 +49,8 @@ namespace boost {
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
@ -61,8 +61,8 @@ namespace boost {
OuterIt!=End; OuterIt!=End;
++OuterIt) ++OuterIt)
{ {
// Sanity check // Sanity check
if( boost::empty(m_Search) ) if( boost::empty(m_Search) )
return result_type( End, End ); return result_type( End, End );
input_iterator_type InnerIt=OuterIt; input_iterator_type InnerIt=OuterIt;
@ -71,7 +71,7 @@ namespace boost {
InnerIt!=End && SubstrIt!=m_Search.end(); InnerIt!=End && SubstrIt!=m_Search.end();
++InnerIt,++SubstrIt) ++InnerIt,++SubstrIt)
{ {
if( !( m_Comp(*InnerIt,*SubstrIt) ) ) if( !( m_Comp(*InnerIt,*SubstrIt) ) )
break; break;
} }
@ -92,7 +92,7 @@ namespace boost {
// find the last match a subsequnce in the sequence ( functor ) // find the last match a subsequnce in the sequence ( functor )
/* /*
Returns a pair <begin,end> marking the subsequence in the sequence. Returns a pair <begin,end> marking the subsequence in the sequence.
If the find fails, returns <End,End> If the find fails, returns <End,End>
*/ */
template<typename SearchIteratorT, typename PredicateT> template<typename SearchIteratorT, typename PredicateT>
@ -105,9 +105,9 @@ namespace boost {
// Construction // Construction
template< typename SearchT > template< typename SearchT >
last_finderF( const SearchT& Search, PredicateT Comp ) : last_finderF( const SearchT& Search, PredicateT Comp ) :
m_Search(begin(Search), end(Search)), m_Comp(Comp) {} m_Search(begin(Search), end(Search)), m_Comp(Comp) {}
last_finderF( last_finderF(
search_iterator_type SearchBegin, search_iterator_type SearchBegin,
search_iterator_type SearchEnd, search_iterator_type SearchEnd,
PredicateT Comp ) : PredicateT Comp ) :
@ -116,8 +116,8 @@ namespace boost {
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
@ -129,21 +129,21 @@ namespace boost {
iterator_traits<ForwardIteratorT>::iterator_category category; iterator_traits<ForwardIteratorT>::iterator_category category;
return findit( Begin, End, category() ); return findit( Begin, End, category() );
} }
private: private:
// forward iterator // forward iterator
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::forward_iterator_tag ) const std::forward_iterator_tag ) const
{ {
typedef ForwardIteratorT input_iterator_type; typedef ForwardIteratorT input_iterator_type;
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
first_finder_type first_finder( first_finder_type first_finder(
m_Search.begin(), m_Search.end(), m_Comp ); m_Search.begin(), m_Search.end(), m_Comp );
result_type M=first_finder( Begin, End ); result_type M=first_finder( Begin, End );
@ -161,9 +161,9 @@ namespace boost {
// bidirectional iterator // bidirectional iterator
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::bidirectional_iterator_tag ) const std::bidirectional_iterator_tag ) const
{ {
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
@ -181,7 +181,7 @@ namespace boost {
InnerIt!=End && SubstrIt!=m_Search.end(); InnerIt!=End && SubstrIt!=m_Search.end();
++InnerIt,++SubstrIt) ++InnerIt,++SubstrIt)
{ {
if( !( m_Comp(*InnerIt,*SubstrIt) ) ) if( !( m_Comp(*InnerIt,*SubstrIt) ) )
break; break;
} }
@ -197,12 +197,12 @@ namespace boost {
iterator_range<search_iterator_type> m_Search; iterator_range<search_iterator_type> m_Search;
PredicateT m_Comp; PredicateT m_Comp;
}; };
// find n-th functor -----------------------------------------------// // find n-th functor -----------------------------------------------//
// find the n-th match of a subsequnce in the sequence ( functor ) // find the n-th match of a subsequnce in the sequence ( functor )
/* /*
Returns a pair <begin,end> marking the subsequence in the sequence. Returns a pair <begin,end> marking the subsequence in the sequence.
If the find fails, returns <End,End> If the find fails, returns <End,End>
*/ */
template<typename SearchIteratorT, typename PredicateT> template<typename SearchIteratorT, typename PredicateT>
@ -215,50 +215,50 @@ namespace boost {
// Construction // Construction
template< typename SearchT > template< typename SearchT >
nth_finderF( nth_finderF(
const SearchT& Search, const SearchT& Search,
unsigned int Nth, unsigned int Nth,
PredicateT Comp) : PredicateT Comp) :
m_Search(begin(Search), end(Search)), m_Search(begin(Search), end(Search)),
m_Nth(Nth), m_Nth(Nth),
m_Comp(Comp) {} m_Comp(Comp) {}
nth_finderF( nth_finderF(
search_iterator_type SearchBegin, search_iterator_type SearchBegin,
search_iterator_type SearchEnd, search_iterator_type SearchEnd,
unsigned int Nth, unsigned int Nth,
PredicateT Comp) : PredicateT Comp) :
m_Search(SearchBegin, SearchEnd), m_Search(SearchBegin, SearchEnd),
m_Nth(Nth), m_Nth(Nth),
m_Comp(Comp) {} m_Comp(Comp) {}
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef ForwardIteratorT input_iterator_type; typedef ForwardIteratorT input_iterator_type;
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
// Sanity check // Sanity check
if( boost::empty(m_Search) ) if( boost::empty(m_Search) )
return result_type( End, End ); return result_type( End, End );
// Instantiate find funtor // Instantiate find funtor
first_finder_type first_finder( first_finder_type first_finder(
m_Search.begin(), m_Search.end(), m_Comp ); m_Search.begin(), m_Search.end(), m_Comp );
result_type M( Begin, Begin ); result_type M( Begin, Begin );
for( unsigned int n=0; n<=m_Nth; ++n ) for( unsigned int n=0; n<=m_Nth; ++n )
{ {
// find next match // find next match
M=first_finder( end(M), End ); M=first_finder( end(M), End );
if ( !M ) if ( !M )
{ {
// Subsequence not found, return // Subsequence not found, return
return M; return M;
} }
} }
@ -276,8 +276,8 @@ namespace boost {
// find a head in the sequence ( functor ) // find a head in the sequence ( functor )
/* /*
This functor find a head of the specified range. For This functor find a head of the specified range. For
a specified N, the head is a subsequence of N starting a specified N, the head is a subsequence of N starting
elements of the range. elements of the range.
*/ */
struct head_finderF struct head_finderF
@ -288,8 +288,8 @@ namespace boost {
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef BOOST_STRING_TYPENAME boost::detail:: typedef BOOST_STRING_TYPENAME boost::detail::
@ -302,7 +302,7 @@ namespace boost {
// Find operation implementation // Find operation implementation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::forward_iterator_tag ) const std::forward_iterator_tag ) const
@ -312,15 +312,15 @@ namespace boost {
input_iterator_type It=Begin; input_iterator_type It=Begin;
for( for(
unsigned int Index=0; unsigned int Index=0;
Index<m_N && It!=End; ++Index,++It ) {}; Index<m_N && It!=End; ++Index,++It ) {};
return result_type( Begin, It ); return result_type( Begin, It );
} }
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::random_access_iterator_tag ) const std::random_access_iterator_tag ) const
@ -342,8 +342,8 @@ namespace boost {
// find a tail in the sequence ( functor ) // find a tail in the sequence ( functor )
/* /*
This functor find a tail of the specified range. For This functor find a tail of the specified range. For
a specified N, the head is a subsequence of N starting a specified N, the head is a subsequence of N starting
elements of the range. elements of the range.
*/ */
struct tail_finderF struct tail_finderF
@ -354,8 +354,8 @@ namespace boost {
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef BOOST_STRING_TYPENAME boost::detail:: typedef BOOST_STRING_TYPENAME boost::detail::
@ -368,7 +368,7 @@ namespace boost {
// Find operation implementation // Find operation implementation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::forward_iterator_tag ) const std::forward_iterator_tag ) const
@ -376,10 +376,10 @@ namespace boost {
typedef ForwardIteratorT input_iterator_type; typedef ForwardIteratorT input_iterator_type;
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
unsigned int Index=0; unsigned int Index=0;
input_iterator_type It=Begin; input_iterator_type It=Begin;
input_iterator_type It2=Begin; input_iterator_type It2=Begin;
// Advance It2 by N incremets // Advance It2 by N incremets
for( Index=0; Index<m_N && It2!=End; ++Index,++It2 ) {}; for( Index=0; Index<m_N && It2!=End; ++Index,++It2 ) {};
@ -391,7 +391,7 @@ namespace boost {
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::bidirectional_iterator_tag ) const std::bidirectional_iterator_tag ) const
@ -401,15 +401,15 @@ namespace boost {
input_iterator_type It=End; input_iterator_type It=End;
for( for(
unsigned int Index=0; unsigned int Index=0;
Index<m_N && It!=Begin; ++Index,--It ) {}; Index<m_N && It!=Begin; ++Index,--It ) {};
return result_type( It, End ); return result_type( It, End );
} }
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
findit( findit(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End, ForwardIteratorT End,
std::random_access_iterator_tag ) const std::random_access_iterator_tag ) const
@ -417,7 +417,7 @@ namespace boost {
typedef ForwardIteratorT input_iterator_type; typedef ForwardIteratorT input_iterator_type;
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < m_N ) ) if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < m_N ) )
return result_type( Begin, End ); return result_type( Begin, End );
return result_type( End-m_N, End ); return result_type( End-m_N, End );
@ -437,29 +437,29 @@ namespace boost {
with an exception that it return range instead of a single with an exception that it return range instead of a single
iterator. iterator.
If bCompress is set to true, adjacent matching tokens are If bCompress is set to true, adjacent matching tokens are
concatenated into one match. concatenated into one match.
*/ */
template< typename PredicateT > template< typename PredicateT >
struct token_finderF struct token_finderF
{ {
// Construction // Construction
token_finderF( token_finderF(
PredicateT Pred, PredicateT Pred,
token_compress_mode_type eCompress=token_compress_off ) : token_compress_mode_type eCompress=token_compress_off ) :
m_Pred(Pred), m_eCompress(eCompress) {} m_Pred(Pred), m_eCompress(eCompress) {}
// Operation // Operation
template< typename ForwardIteratorT > template< typename ForwardIteratorT >
iterator_range<ForwardIteratorT> iterator_range<ForwardIteratorT>
operator()( operator()(
ForwardIteratorT Begin, ForwardIteratorT Begin,
ForwardIteratorT End ) const ForwardIteratorT End ) const
{ {
typedef iterator_range<ForwardIteratorT> result_type; typedef iterator_range<ForwardIteratorT> result_type;
ForwardIteratorT It=std::find_if( Begin, End, m_Pred ); ForwardIteratorT It=std::find_if( Begin, End, m_Pred );
if( It==End ) if( It==End )
{ {
return result_type( End, End ); return result_type( End, End );
@ -471,11 +471,11 @@ namespace boost {
if( m_eCompress==token_compress_on ) if( m_eCompress==token_compress_on )
{ {
// Find first non-matching character // Find first non-matching character
while( m_Pred(*It2) && It2!=End ) ++It2; while( It2!=End && m_Pred(*It2) ) ++It2;
} }
else else
{ {
// Advance by one possition // Advance by one possition
++It2; ++It2;
} }
@ -502,18 +502,18 @@ namespace boost {
typedef iterator_range<input_iterator_type> result_type; typedef iterator_range<input_iterator_type> result_type;
// Construction // Construction
range_finderF( range_finderF(
input_iterator_type Begin, input_iterator_type Begin,
input_iterator_type End ) : m_Range(Begin, End) {} input_iterator_type End ) : m_Range(Begin, End) {}
range_finderF(const iterator_range<input_iterator_type>& Range) : range_finderF(const iterator_range<input_iterator_type>& Range) :
m_Range(Range) {} m_Range(Range) {}
// Operation // Operation
template< typename ForwardIterator2T > template< typename ForwardIterator2T >
iterator_range<ForwardIterator2T> iterator_range<ForwardIterator2T>
operator()( operator()(
ForwardIterator2T, ForwardIterator2T,
ForwardIterator2T ) const ForwardIterator2T ) const
{ {
return m_Range; return m_Range;