Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-06-13 15:09:15


Beman Dawes wrote:

> The "too similar" problem with overloading predicate functions on
> directory_iterator is that two very similar calls have different
> behavior:
> if ( is_directory( *itr ) ) // uses current status
>
> if ( is_directory( itr ) ) // uses cached status, which may be very
> stale
>
> That looks like a race-condition trap for unwary users.

I could argue that the second form is less "trappy" for unwary users,
actually, because all is_directory( itr ) calls will always yield the same
value (and exists(itr) will never yield false for an enumerated item). This
comes into play in situations like:

void f( itr )
{
    if( is_directory(itr) )
    {
        g( itr );
    }
    else
    {
        h( itr );
    }
}

void g( itr )
{
    if( is_directory(itr) )
    {
        // ...
    }
    else
    {
        // ...
    }
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk