Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-10-04 11:24:02


From: Angus Leeming <angus.leeming_at_[hidden]>
> Rob Stewart wrote:
> >> This is, in essence, what I am proposing. I have now reworked the
> >> interface following Gennadiy's suggestion. Here's a glob_iterator that
> >> can recurse down directories:
[snipped code]
> > I think you misunderstood what Gennadiy meant. (If not, I think
> > this is a good idea, anyway.) Your function should accept an
> > output iterator through which you save the results. That enables
> > the caller to decide where the results go instead of you deciding
> > that they go into a list which then must be iterated. Thus, I'm
> > proposing something like this:
> >
> > template <typename OutIt, typename Char>
> > OutIt
> > glob(OutIt & out, std::basic_string<Char> const & pattern,
> > filesystem::path const & pathname, glob_flags flags);
> >
> > Appropriate output iterators can forward the matches to a
> > collection, to a GUI control, to a file, etc.
>
> As for the output iterator idea, I don't see how to use it. For example,
> with my suggestion I could populate an STL container with:
>
> namespace fs = filesystem;
> std::list<fs::path> const matches(
> glob_iterator("*.cpp", fs::path("."), glob_brace),
> glob_iterator());
>
> How do I do that with your idea? Once you've explained it, can you tell me
> why it's better than glob_iterator, above?

Gennadiy already weighed in on my interpretation of his
statement. As to what I've suggested, you already had code that
built a std::list -- your original version, IIRC. Where you
appended to the list, you would assign to the dereferenced output
iterator. That deref/assignment can be coded to do many things
by the author of the output iterator, including appending to a
std::list.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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