Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-04-01 10:13:28

From: Beman Dawes <bdawes_at_[hidden]>
> At 07:17 PM 3/31/2005, Peter Dimov wrote:
> >
> >If you make 'exists' throw an exception, you will create a demand for a
> >'preexists' query that will be used to detect whether the actual 'exists'
> >will throw.
> I agree, but don't think that has to lead to a "no" answer. One plan would
> be to supply a status query function, perhaps named status(), which would
> never throw and which would return a bitmask which could be queried as to
> the exact attributes that apply. Including an attribute that indicates one
> of these oddball errors has occurred. As with POSIX, there would presumably
> be an lstat()-like query function that did not resolve symbolic links.

I think a single, overloaded function can quite easily accomodate
everything and still be easy to use:

struct no_throw_t { };
static no_throw_t nothrow;

struct resolve_symlinks_t { };
static resolve_symlinks_t resolve_symlinks;

enum attributes { ... };

stat(path); // !resolves, throws

stat(path, no_throw_t); // !resolves, !throws

stat(path, resolve_symlinks_t); // resolves, throws

stat(path, resolve_symlinks_t, no_throw_t); // resolves, !throws

> Presumably then exists() and the is_x() functions would be specified in
> terms of status() and lstatus() results. So in effect exists() and the
> is_x() functions are conveniences, very useful in many but not all cases,
> and safe to use casually since obscure errors will cause exceptions.

Sounds great to me!

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at