Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-11-11 16:02:06


Walter Landry <wlandry_at_[hidden]> writes:

> I have been using boost::filesystem for a little while, and I am
> finding that it would be nice to be able to just work on the paths in
> the directory as a std::list or std::vector. Boost::filesystem
> currently just provides an iterator, not the complete list.
>
> I did a little survey of other filesystem libraries. Qt, gnome-vfsmm,
> Emacs-lisp, python, and java provide a way of getting the entire list
> of paths in a directory in addition to an iterator. Perl, Ruby,
> wxWindows, and POSIX do not.
>
> This subject is touched upon lightly in the FAQ (directory handles),
> but I can't find a good rationale for not providing such a function.
> The first downside I can think of is that it can make code a little
> longer, though not always.

It's greedily-evaluated; that's one problem. If you want to be able
to call begin() on something, you can just wrap directory_iterator in
another object:

    struct dir
    {
        dir(directory_iterator i) // intentional implicit conversion
          : start(i) {}
        directory_iterator begin() const { return start; }
        directory_iterator end() const { return directory_iterator(); }
     private:
        directory_iterator i;
    };

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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