Vladimir Grigoriev
2009-12-16 12:38:23 UTC
It is interesting: Does the C++ standard say explicitly which comparision
operator should be used inside the algorithm std::find or it is
implementation dependent?
For example I can write the find() using an inequality operator
template <typename InputIterator, typename T>
InputIterator find( InputIterator first, InputIterator last, const T
&value )
{
while ( ( first != last ) && ( *first != value ) ) ++ first;
return ( first );
}
Or I can write the same using an equality operator
template <typename InputIterator, typename T>
InputIterator find( InputIterator first, InputIterator last, const T
&value )
{
for ( ; first != last; ++ first )
{
if ( *first == value ) break;
}
return ( first );
}
Vladimir Grigoriev
operator should be used inside the algorithm std::find or it is
implementation dependent?
For example I can write the find() using an inequality operator
template <typename InputIterator, typename T>
InputIterator find( InputIterator first, InputIterator last, const T
&value )
{
while ( ( first != last ) && ( *first != value ) ) ++ first;
return ( first );
}
Or I can write the same using an equality operator
template <typename InputIterator, typename T>
InputIterator find( InputIterator first, InputIterator last, const T
&value )
{
for ( ; first != last; ++ first )
{
if ( *first == value ) break;
}
return ( first );
}
Vladimir Grigoriev