A
Alf P. Steinbach
Given
template < typename InputIterator1, typename InputIterator2 >
bool disjoint ( InputIterator1 from1, InputIterator1 to1,
InputIterator2 from2, InputIterator2 to2 ) {
while ( from1 != to1 && from2 != to2 ) {
if ( *from1 < *from2 ) {
++ from1;
continue;
}
if ( *from2 < *from1 ) {
++ from2;
continue;
}
return ( false );
}
return ( true );
}
and as an alternative, by some other programmer:
template <typename InputIter1, typename InputIter2>
bool disjoint(InputIter1 first1, InputIter1 last1,
InputIter2 first2, InputIter2 last2)
{
while (first1 != last1 && first2 != last2)
if (*first1 < *first2)
++first1;
else if (*first2 < *first1)
++first2;
else // *first1 == *first2
return false;
return true;
}
Is the first version a case for 'continue', an example where it's natural/good?
Neither code snippet is mine (I'd do the second version but with curly braces).
Cheers, & hoping for some enlightenment,
- Alf
template < typename InputIterator1, typename InputIterator2 >
bool disjoint ( InputIterator1 from1, InputIterator1 to1,
InputIterator2 from2, InputIterator2 to2 ) {
while ( from1 != to1 && from2 != to2 ) {
if ( *from1 < *from2 ) {
++ from1;
continue;
}
if ( *from2 < *from1 ) {
++ from2;
continue;
}
return ( false );
}
return ( true );
}
and as an alternative, by some other programmer:
template <typename InputIter1, typename InputIter2>
bool disjoint(InputIter1 first1, InputIter1 last1,
InputIter2 first2, InputIter2 last2)
{
while (first1 != last1 && first2 != last2)
if (*first1 < *first2)
++first1;
else if (*first2 < *first1)
++first2;
else // *first1 == *first2
return false;
return true;
}
Is the first version a case for 'continue', an example where it's natural/good?
Neither code snippet is mine (I'd do the second version but with curly braces).
Cheers, & hoping for some enlightenment,
- Alf